Symfony2自定义翻译文件名

时间:2017-01-13 13:24:34

标签: php symfony translation

Symfony2要求翻译文件名的格式为 domain.locale.loader (例如messages.en_GB.po)。

在旧系统中,我将文件存储为en_GB.po,因此我想知道是否有一种简单的方法可以让Symfony加载这些文件。

1 个答案:

答案 0 :(得分:0)

您可以拥有自己的加载程序并在加载文件时添加域名:

大概就是这样:

    $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

相关问题