Symfony 忽略JMS I18n路由转换
我正在尝试使用JMSI18nRoutingBundle来翻译我的路线。我已经安装并配置了它,如文档中所示: composer.json:Symfony 忽略JMS I18n路由转换,symfony,routing,routes,symfony-2.4,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_ro
"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"
这样,翻译被提取到AcmeCoreBundle/Resources/translations
中的routes.fr.yml
文件中。该文件包含所有区域设置中所有路由的翻译,而不是像命令中指定的那样,仅包含fr
区域设置中AcmeCoreBundle
的路由,但哦,它可以工作
但是,当我执行php应用程序/控制台路由器: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.yml
和routes.en.yml
之间的翻译分离开来,这对我来说没有任何效果…,但我通过将路由的翻译文件移动到“应用程序/资源/翻译”
这对我很有用:
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
这里也是一样,我无法让它工作。当我遇到问题时,我切换到另一个包。但过了一段时间,我发现它不足以满足我的需要,我真的需要JMS包,所以我回来尝试让它工作。最后我找到了一个解决办法:我使用命令
php应用程序/控制台翻译:extract fr——enable extract或者=jms_i18n_routing--bundle=“AppCoreBundle”-domain=“routes”
其中AppCoreBundle
可以是任何bundle,因为提取器提取所有bundle的所有翻译。然后我手工编辑生成的文件,删除所有en_fr翻译并自己翻译路由。