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
You can look at the file lib/Cake/I18n/L10n.php, to know how to call each language.
settings for German:
=> app/Locale/deu/LC_MESSAGES/default.po