YAML formatter
YAML translation files with ICU messages for eugene-erg/icu-i18n-translator, as Symfony keeps them in translations/messages+intl-icu.en.yaml.
bash
composer require eugene-erg/yaml-formatter-icu-i18n-translatorphp
use EugeneErg\YamlFormatterIcuI18nTranslator\YamlFormatter;
$translator = new Translator(/* … */, formatters: ['yaml' => new YamlFormatter()]);
$translator->addFile('yaml', 'messages', file_get_contents('translations/messages+intl-icu.en.yaml'), 'en');
file_put_contents('translations/messages+intl-icu.ru.yaml', $translator->getFile('yaml', 'messages', 'ru'));yaml
cart:
title: Cart
items: '{count, plural, one {# item} other {# items}}'
app.menu.open: Open- Only plain data is read.
!php/objectand custom tags are refused, not built. - Keys keep their order and are not split at dots, so flat Symfony keys stay flat.
- Writing uses
symfony/yaml: values are quoted where YAML needs it ({…},#,:, numbers,yes), and multi-line messages are written as literal blocks (|-). A written file reads back the same. - Values that are not text are refused with the key named. A number or a boolean is not a message, so quote it:
code: '404'. An empty value is refused too. - Indentation is 4 spaces by default; set
indent: 2for 2. - Messages are ICU by default; pass another
MessageSyntaxInterfacefor other syntaxes.
Development
bash
composer check # pint --test, phpstan (level max, strict rules) and phpunit
composer coverageLicense
MIT
From the README.md of EugeneErg/yaml-formatter-icu-i18n-translator · composer require eugene-erg/yaml-formatter-icu-i18n-translator