JMS I18n路由转换被忽略

时间:2014-05-28 19:22:01

标签: symfony routing routes symfony-2.4

我试图使用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

然后我试图提取路线的翻译。 doc中给出的命令

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文件中提取。该文件包含所有语言环境中所有路由的转换,而不仅仅是命令中指定的AcmeCoreBundle语言环境中fr的路由,但是哦,它可以工作...... < / p>

但是,当我执行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之间的翻译分开,没有任何效果......

1 个答案:

答案 0 :(得分:0)

这也发生在我身上,但我通过将路线的翻译文件移动到&#34; app / Resources / translations&#34;

来解决这个问题。

这对我有用:

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
相关问题