【问题标题】:JMS I18n routes translations are ignoredJMS I18n 路由转换被忽略
【发布时间】:2014-05-28 19:22:01
【问题描述】:

我正在尝试使用 JMSI18nRoutingBundle 来翻译我的路线。我已经安装并配置了它,就像它在文档中显示的那样:

composer.json:

"jms/i18n-routing-bundle": "1.1.*@dev",

AppKernel.php:

new JMS\I18nRoutingBundle\JMSI18nRoutingBundle(),
new JMS\TranslationBundle\JMSTranslationBundle(),

还有 config.yml:

jms_i18n_routing:
    default_locale: %locale%
    locales: [en, fr]
    catalogue: routes
    strategy: custom

然后我尝试提取路线的翻译。文档中给出的命令

php app/console translation:extract fr --enable-extractor=jms_i18n_routing

根本不起作用,但我在互联网上发现这个命令效果更好:

php app/console translation:extract fr --enable-extractor=jms_i18n_routing --bundle="TeduleCoreBundle" --domain="routes"

这样,翻译被提取到routes.fr.yml 文件AcmeCoreBundle/Resources/translations 中。该文件包含所有语言环境中所有路由的翻译,而不仅仅是命令中指定的fr 语言环境中AcmeCoreBundle 的路由,但是哦,好吧,它可以工作...

但是,当我执行php app/console router:debug 时,没有任何路线被翻译。相反,我最终得到了这样的结果:

en_fr__RG__tedule_app_account_profile        ANY      ANY    ANY /myaccount
en__RG__tedule_app_account_profile           ANY      ANY    ANY /myaccount
fr__RG__tedule_app_account_profile           ANY      ANY    ANY /myaccount
en_fr__RG__tedule_app_account_notifications  ANY      ANY    ANY /myaccount/notifications
en__RG__tedule_app_account_notifications     ANY      ANY    ANY /myaccount/notifications
fr__RG__tedule_app_account_notifications     ANY      ANY    ANY /myaccount/notifications
en_fr__RG__tedule_app_account_password       ANY      ANY    ANY /myaccount/password
en__RG__tedule_app_account_password          ANY      ANY    ANY /myaccount/password
fr__RG__tedule_app_account_password          ANY      ANY    ANY /myaccount/password

如您所见,每条路线出现 3 次(en_fr、en 和 fr),并且该模式并未按照我在 routes.fr.yml 文件中所写的内容进行翻译。

我尝试清除缓存,将routes.fr.yml 文件放入app/Resources/translations,分离两个文件routes.fr.ymlroutes.en.yml 之间的翻译,没有任何效果...

【问题讨论】:

  • 这里一样,我不能让它工作。
  • 当我遇到问题时,我切换到另一个捆绑包。但过了一段时间,我发现它不足以满足我的需求,我真的需要 JMS 包,所以我回来尝试让它工作。最后我找到了一个解决方法:我使用命令php app/console translation:extract fr --enable-extractor=jms_i18n_routing --bundle="AppCoreBundle" --domain="routes",其中AppCoreBundle 可以是任何包,因为提取器会提取所有包的所有翻译。然后我手动编辑生成的文件,删除所有的 en_fr 翻译并自己翻译路线。

标签: symfony routing routes symfony-2.4


【解决方案1】:

这也发生在我身上,但我通过将路由的翻译文件移动到“app/Resources/translations”解决了这个问题

这对我有用:

php app/console translation:extract en_US --bundle=MyBundle --enable-extractor=jms_i18n_routing --output-format=xliff --domain=routes --keep --output-dir=app/Resources/translations

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-06-02
    • 2011-03-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-07
    • 1970-01-01
    • 2014-04-11
    相关资源
    最近更新 更多