5

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
Community
  • 1
  • 1
Christian Strang
  • 8,470
  • 5
  • 42
  • 53

2 Answers2

9

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

del_dan
  • 873
  • 1
  • 9
  • 16
6

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     |
icc97
  • 11,395
  • 8
  • 76
  • 90
mark
  • 21,691
  • 3
  • 49
  • 71
  • 1
    Ah, now it works. Wasn't obvious to me that I have to use the "T" value from the file, too bad that this is not mentioned in the documentation as I think a lot of other CakePHP users might not know that. – Christian Strang Apr 06 '12 at 22:26
  • Thanks for your answer! I can only mark one as the correct answer, I took del_dan's one because of the reference to the L10n file. – Christian Strang Apr 06 '12 at 22:28
  • 1
    no problem. as for the documentation: you can participate by pushing to the github rep: https://github.com/cakephp/docs - so you can put the missing information in. – mark Apr 06 '12 at 22:29