CsvFileDumper.php
1 month ago
DumperInterface.php
2 years ago
FileDumper.php
1 month ago
IcuResFileDumper.php
1 month ago
IniFileDumper.php
1 month ago
JsonFileDumper.php
1 month ago
MoFileDumper.php
1 month ago
PhpFileDumper.php
1 month ago
PoFileDumper.php
1 month ago
QtFileDumper.php
1 month ago
XliffFileDumper.php
1 month ago
YamlFileDumper.php
1 month ago
YamlFileDumper.php
55 lines
| 1 | <?php |
| 2 | |
| 3 | /* |
| 4 | * This file is part of the Symfony package. |
| 5 | * |
| 6 | * (c) Fabien Potencier <fabien@symfony.com> |
| 7 | * |
| 8 | * For the full copyright and license information, please view the LICENSE |
| 9 | * file that was distributed with this source code. |
| 10 | */ |
| 11 | namespace IAWPSCOPED\Symfony\Component\Translation\Dumper; |
| 12 | |
| 13 | use IAWPSCOPED\Symfony\Component\Translation\Exception\LogicException; |
| 14 | use IAWPSCOPED\Symfony\Component\Translation\MessageCatalogue; |
| 15 | use IAWPSCOPED\Symfony\Component\Translation\Util\ArrayConverter; |
| 16 | use IAWPSCOPED\Symfony\Component\Yaml\Yaml; |
| 17 | /** |
| 18 | * YamlFileDumper generates yaml files from a message catalogue. |
| 19 | * |
| 20 | * @author Michel Salib <michelsalib@hotmail.com> |
| 21 | * @internal |
| 22 | */ |
| 23 | class YamlFileDumper extends FileDumper |
| 24 | { |
| 25 | private string $extension; |
| 26 | public function __construct(string $extension = 'yml') |
| 27 | { |
| 28 | $this->extension = $extension; |
| 29 | } |
| 30 | /** |
| 31 | * {@inheritdoc} |
| 32 | */ |
| 33 | public function formatCatalogue(MessageCatalogue $messages, string $domain, array $options = []) : string |
| 34 | { |
| 35 | if (!\class_exists(Yaml::class)) { |
| 36 | throw new LogicException('Dumping translations in the YAML format requires the Symfony Yaml component.'); |
| 37 | } |
| 38 | $data = $messages->all($domain); |
| 39 | if (isset($options['as_tree']) && $options['as_tree']) { |
| 40 | $data = ArrayConverter::expandToTree($data); |
| 41 | } |
| 42 | if (isset($options['inline']) && ($inline = (int) $options['inline']) > 0) { |
| 43 | return Yaml::dump($data, $inline); |
| 44 | } |
| 45 | return Yaml::dump($data); |
| 46 | } |
| 47 | /** |
| 48 | * {@inheritdoc} |
| 49 | */ |
| 50 | protected function getExtension() : string |
| 51 | { |
| 52 | return $this->extension; |
| 53 | } |
| 54 | } |
| 55 |