Symfony2 自定义翻译文件名
Symfony2 custom translation filenames
Symfony2 要求翻译文件名的格式为 domain.locale.loader(例如 messages.en_GB.po
)。
在遗留系统中,我将文件存储为 en_GB.po
,所以我想知道是否有一种简单的方法可以让 Symfony 加载这些文件。
您可以拥有自己的加载程序并在加载文件时添加域:
大致是这样的:
$this->translator->addLoader('yaml', new \Symfony\Component\Translation\Loader\YamlFileLoader());
$this->translator->addResource('yaml', __DIR__.'/../../resources/translations/en_US.yml', 'en_US', 'addressing');
$this->translator->addResource('yaml', __DIR__.'/../../resources/translations/es_ES.yml', 'es_ES', 'addressing');
您可以在您的应用程序的引导程序中加载这些,并为其提供服务。
您可以在这里阅读更多内容:
http://symfony.com/doc/current/components/translation/custom_formats.html
Symfony2 要求翻译文件名的格式为 domain.locale.loader(例如 messages.en_GB.po
)。
在遗留系统中,我将文件存储为 en_GB.po
,所以我想知道是否有一种简单的方法可以让 Symfony 加载这些文件。
您可以拥有自己的加载程序并在加载文件时添加域:
大致是这样的:
$this->translator->addLoader('yaml', new \Symfony\Component\Translation\Loader\YamlFileLoader());
$this->translator->addResource('yaml', __DIR__.'/../../resources/translations/en_US.yml', 'en_US', 'addressing');
$this->translator->addResource('yaml', __DIR__.'/../../resources/translations/es_ES.yml', 'es_ES', 'addressing');
您可以在您的应用程序的引导程序中加载这些,并为其提供服务。
您可以在这里阅读更多内容: http://symfony.com/doc/current/components/translation/custom_formats.html