CsvFileDumper.php
2 months ago
DumperInterface.php
2 months ago
FileDumper.php
2 months ago
IcuResFileDumper.php
2 months ago
IniFileDumper.php
2 months ago
JsonFileDumper.php
2 months ago
MoFileDumper.php
2 months ago
PhpFileDumper.php
2 months ago
PoFileDumper.php
2 months ago
QtFileDumper.php
2 months ago
XliffFileDumper.php
2 months ago
YamlFileDumper.php
2 months ago
YamlFileDumper.php
54 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 ProfilePressVendor\Symfony\Component\Translation\Dumper; |
| 12 | |
| 13 | use ProfilePressVendor\Symfony\Component\Translation\Exception\LogicException; |
| 14 | use ProfilePressVendor\Symfony\Component\Translation\MessageCatalogue; |
| 15 | use ProfilePressVendor\Symfony\Component\Translation\Util\ArrayConverter; |
| 16 | use ProfilePressVendor\Symfony\Component\Yaml\Yaml; |
| 17 | /** |
| 18 | * YamlFileDumper generates yaml files from a message catalogue. |
| 19 | * |
| 20 | * @author Michel Salib <michelsalib@hotmail.com> |
| 21 | */ |
| 22 | class YamlFileDumper extends FileDumper |
| 23 | { |
| 24 | private $extension; |
| 25 | public function __construct(string $extension = 'yml') |
| 26 | { |
| 27 | $this->extension = $extension; |
| 28 | } |
| 29 | /** |
| 30 | * {@inheritdoc} |
| 31 | */ |
| 32 | public function formatCatalogue(MessageCatalogue $messages, string $domain, array $options = []) |
| 33 | { |
| 34 | if (!class_exists(Yaml::class)) { |
| 35 | throw new LogicException('Dumping translations in the YAML format requires the Symfony Yaml component.'); |
| 36 | } |
| 37 | $data = $messages->all($domain); |
| 38 | if (isset($options['as_tree']) && $options['as_tree']) { |
| 39 | $data = ArrayConverter::expandToTree($data); |
| 40 | } |
| 41 | if (isset($options['inline']) && ($inline = (int) $options['inline']) > 0) { |
| 42 | return Yaml::dump($data, $inline); |
| 43 | } |
| 44 | return Yaml::dump($data); |
| 45 | } |
| 46 | /** |
| 47 | * {@inheritdoc} |
| 48 | */ |
| 49 | protected function getExtension() |
| 50 | { |
| 51 | return $this->extension; |
| 52 | } |
| 53 | } |
| 54 |