5
votes

I use <?php echo __("this is my string"); ?> inside my views to display text in multiple languages. I created a .po-file directory for german:

=> app/Locale/ger/LC_MESSAGES/default.po

msgid "this is my string"

msgstr "dies ist meine zeichenkette"

When I add Configure::write('Config.language','ger'); to my AppController.php beforeFilter function the text still remains "this is my string". Even if I create a .po for english with a different msgstr the text still remains the same.

Do I have to change a specific setting to activate the translation?


I have a follow up problem: I added Configure::write('Config.language','eng'); to core.php to set my default language but now I can't change the value, even if I try to override it in AppController.php beforeFilter with:

Configure::write('Config.language', 'deu'); //'de' also doesn't work
CakeSession::write('Config.language', 'deu'); //'de' also doesn't work

If I change the value in core.php it works perfectly fine but once set in core.php I cant change it.

solved: ah, I forgot to add parent::beforeFilter(); inside the beforeFilter function of all the controllers.


Additional information:

  • If you want to define a default language (and you usually will), add Configure::write('Config.language', 'eng'); to the core.php
2

2 Answers

9
votes

You can look at the file lib/Cake/I18n/L10n.php, to know how to call each language.

settings for German:

Configure::write('Config.language','de');

=> app/Locale/deu/LC_MESSAGES/default.po

6
votes

its "deu" not "ger"

CakePHP uses the official (T) codes from http://www.loc.gov/standards/iso639-2/php/code_list.php, for CakePHP 1.3 it is documented under Internationalizing Your Application:

The three-character locale codes conform to the ISO 639-2 standard, although if you create regional locales (en_US, en_GB, etc.) cake will use them if appropriate.

ISO 639-2 |  ISO 639-1 | English name | French name | German name |
Code      |  Code      | of Language  | of Language | of Language |
-------------------------------------------------------------------
ger (B)   |            |              |             |             |
deu (T)   |  de        | German       | allemand    | Deutsch     |