| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
namespace Symfony\Component\Translation\Dumper; |
| 13 |
|
| 14 |
use Symfony\Component\Translation\Exception\LogicException; |
| 15 |
use Symfony\Component\Translation\MessageCatalogue; |
| 16 |
use Symfony\Component\Translation\Util\ArrayConverter; |
| 17 |
use Symfony\Component\Yaml\Yaml; |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
class YamlFileDumper extends FileDumper |
| 25 |
{ |
| 26 |
public function __construct( |
| 27 |
private string $extension = 'yml', |
| 28 |
) { |
| 29 |
} |
| 30 |
|
| 31 |
public function formatCatalogue(MessageCatalogue $messages, string $domain, array $options = []): string |
| 32 |
{ |
| 33 |
if (!class_exists(Yaml::class)) { |
| 34 |
throw new LogicException('Dumping translations in the YAML format requires the Symfony Yaml component.'); |
| 35 |
} |
| 36 |
|
| 37 |
$data = $messages->all($domain); |
| 38 |
|
| 39 |
if (isset($options['as_tree']) && $options['as_tree']) { |
| 40 |
$data = ArrayConverter::expandToTree($data); |
| 41 |
} |
| 42 |
|
| 43 |
if (isset($options['inline']) && ($inline = (int) $options['inline']) > 0) { |
| 44 |
return Yaml::dump($data, $inline); |
| 45 |
} |
| 46 |
|
| 47 |
return Yaml::dump($data); |
| 48 |
} |
| 49 |
|
| 50 |
protected function getExtension(): string |
| 51 |
{ |
| 52 |
return $this->extension; |
| 53 |
} |
| 54 |
} |