Trouble with Internationalization on CakePHP 2.0

隐身守侯 提交于 2019-12-08 04:41:02

问题


The internationalization process is not working.

I ran cake i18n export. After that I put the translations into the file ".po" in the folder app/locale/por/LC_MESSAGES/default.po..

I called the method beforeFilter() in the AppController Configure::write('Config.language', 'por');.

But the translation isn't shown in __()-methods.


回答1:


Here are some possible suggestions:

• Clear the Cake cache in PATH_YOUR_APP/tmp/cache. Delete the files in models and persistent, but not the directories itself. I believe persistent is where the localised strings are saved, but empty both to be sure.

• Do you override the beforeFilter in any of your controllers, other than the AppController? If so call parent::beforeFilter(); in the controller's beforeFilter method, before processing other stuff, like so:

public function beforeFilter() {
  parent:beforeFilter();
  //Do stuff here
}

• How did you create the translation files? Is there a .mo file in the .po directory as well? I believe directly editing .po and .pot files is not recommended due to character encoding issues (but I could be mistaken). Poedit is a good tool for manipulating .po files, though it could be more robust.




回答2:


Some more things to check

  1. Check whether your browser's language is selected properly Portuguese as the first language of choice
  2. Is your msgid and msgstr keys in individual lines and properly enclosed the text within double quotes?
  3. I'm not a CakePHP expert, but try moving the configuration to the bootstrap.php. Your code seems logical there.


来源:https://stackoverflow.com/questions/7954199/trouble-with-internationalization-on-cakephp-2-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!