duanfu3884 2014-12-28 17:14
浏览 40
已采纳

Symfony 2:转换为默认语言环境

I'm experimenting on Symfony 2 Translation Component. My default locale is el_GR and my alternate locale is en_US. I 've set up my config.yml, I've created 2 translation files: messages.el_GR.yml and messages.en_US.yml and then cleared app/cache. I have translated the word Symfony in both locales. So when I use the command php app/console translation:debug en_US abcNikBundle I get:

State | Id       | Message Preview (en_US) | Fallback Message Preview (el_GR)
      | Symfony  | Symfony_US              | Symfony_GR

So in a twig template I write

{{ 'Symfony'|trans({},'messages') }} 

It works fine when I use the en_US locale, (it prints Symfony_US) but When I use my default locale (el_GR), it prints Symfony instead of Symfony_GR. Can it be done somehow?

  • 写回答

1条回答 默认 最新

  • douzhi4311 2014-12-28 20:11
    关注

    Make sure your cache is completely deleted. You probably reset the cache after adding the English translation but not your fallback. See the Symfony documentation for more info:

    Each time you create a new translation resource (or install a bundle that includes a translation resource), be sure to clear your cache so that Symfony can discover the new translation resources:

    Sometimes just running the cache:clear command fails for me in which case I just manually delete the contents of the app/cache directory.

    Also, if a translation cannot be found it is logged in debug mode in the translation channel (dev.translation.log) - check your logs to see if it couldn't find the translation. Also, you don't have to specify 'messages' since that's the default, you can just do {{ 'Symfony'|trans }}

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改