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 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥15 可见光定位matlab仿真