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 }}

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

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?