CakePp本地化 [英] CakePhp localization

查看:137
本文介绍了CakePp本地化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在网站上设置本地化,但我遇到了一些麻烦。



我找到了一个教程,这正是我需要的: a href =http://nuts-and-bolts-of-cakephp.com/2008/11/28/cakephp-url-based-language-switching-for-i18n-and-l10n-internationalization-and-localization/ rel =nofollow> http://nuts-and-bolts-of-cakephp.com/2008/11/28/cakephp-url-based-language-switching-for-i18n-and-l10n-internationalization-and -localization /
(直接使用主机名后的语言)。



所以我做了这个网站上写的一切: / p>


  1. 我生成了一个pot文件,使用这个pot文件,我使用PoEdit创建了三个po文件(eng,ger和fre)翻译两个测试字段。

  2. 我已将这些文件放入app / locale / eng | fre | ger

  3. :: connect('/:language /:controller /:action / *',array(),array('language'=>'[az] {3}'));在正确的文件中

  4. 我已设置默认语言:Configure :: write('Config.language','fre');

  5. 我创建了三个链接来改变语言:link('Français',array('language'=>'fre')); ?>

  6. 我在appController中设置了_setLanguage方法,并在beforeFilter()中调用它

  7. 我创建了一个appHelper不必每次指定当前语言

我的链接生成的很好,我没有任何异常/错误,我的本地文件是可读的,但是当我去模板,我试图使用variable()我只是看到testTranslation作为文本,没有翻译的文本。



这不工作?看起来找不到我的文件,但我不知道为什么:(



任何帮助将非常感激!



编辑:我用cakePhp做了一些调试,看起来当调用i18n.php文件的方法translate时,我收到一个$ domain = default_ger var。我的翻译都在default.po文件中,并且我想他正在搜索default_ger.po?为什么这个?我怎么能强迫它读取default.po文件?



编辑:我发现了一些东西:我有一个问题,我的控制器,我忘了在我的孩子控制器中声明parent :: beforeFilter(),然后在控制器中的方法没有被调用,并且语言总是德国的一个。和英语工作正常,但德国仍然只显示关键,而不是我在翻译文件中的值这是真的很奇怪,我删除了缓存中的所有文件,删除我的/ app / locale / ger文件夹,并将我的/ app / locale / fre复制到/ app / locale / ger(不更改任何文件),这仍然不工作。什么可以不同?

解决方案

我终于找到了问题:



因为德语总是被使用的(因为当将语言改为德语时它会工作一次,并通过cookie注册它)。



除德语之外的所有其他语言正在正确显示我的值。



所以我搜索这个问题,我试图使用deu而不是ger

语言环境文件夹必须是deu,语言值可以是deu或ger。



这很奇怪,因为对于法语,我有一个fre(FREnch),而不是fra(FRAnçais),这是工作。

无论如何,这个工作与此更改


I'm setting the localization on a website, but I've some trouble.

I've found a tutorial, which does exactly what I need: http://nuts-and-bolts-of-cakephp.com/2008/11/28/cakephp-url-based-language-switching-for-i18n-and-l10n-internationalization-and-localization/ (having directly the language after the hostname).

So I've done everything which is written on this website:

  1. I've generated a pot file, with this pot file, I create three po files(eng, ger and fre) with PoEdit, I translated two tests fields.
  2. I've put those files into app/locale/eng|fre|ger
  3. I've added the route Router::connect('/:language/:controller/:action/*', array(),array('language' => '[a-z]{3}')); in the correct file
  4. I've set the default language: Configure::write('Config.language', 'fre');
  5. I've created three links to change the language: link('Français', array('language'=>'fre')); ?>
  6. I've set the _setLanguage method in my appController(and calling it in the beforeFilter())
  7. I've created an appHelper to don't have to specify everytime the current language

My links are well generated, I don't have any exception/errors, my locals files are readable, but when I go on the template where I try to use variable( ) I just see "testTranslation" as text, no translated text.

Why this isn't working? Looks like it can't find my files but I don't know why :(

Any help would be really appreciated!

Edit: I did some debugging with cakePhp, and it appears that when the method translate of the i18n.php file is called, I receive a $domain = default_ger var. My translations are all in default.po files, and I suppose that he is searching into default_ger.po? why this? how can i force it to read in the default.po file?

Edit: I found something: I had a problem with my controller, I forgot to declare the parent::beforeFilter() in my children controller, then the method in the controller wasn't called and the language was always the german one. After I fixed this, the french and the english are working fine, but the german is still only displaying key and not values that I've in the translation file. This is really weird, I've deleted all files in the cache, deleted my /app/locale/ger folder and copied my /app/locale/fre to /app/locale/ger(without changing anything in files) and this still doesn't work. What can be different?

解决方案

I finally found the problem:

My App controller wasn't called, so the German language was always used(because it worked once when changing the language to german, and register it through cookies).

All other languages than german were displaying correctly my values.

So I searched about this problem, and I tried to use "deu" instead of "ger", and it worked!

The locale folder has to be "deu", the language value can be deu or ger.

This is very strange, because for the french, I've a "fre"(FREnch) and not a "fra"(FRAnçais), and this is working.

Anyway, this work with this change

这篇关于CakePp本地化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆