繁体   English   中英

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');

您可以在应用程序的boostrapping上加载这些内容,并为其提供服务。

您可以在这里阅读更多内容: http//symfony.com/doc/current/components/translation/custom_formats.html

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM