I'm using CakePHP v2.5.6 and I'm following this documentation on CakePHP localization. I've read it 100 times but it still isn't working!
Using the cake console i18n
task, I've created the following files...
app/Locale/default.pot
app/Locale/fra/LC_MESSAGES/default.po
app/Locale/fra/LC_MESSAGES/default.mo
...I used Poedit to translate a few strings (for testing) purposes:
In bootstrap.php I have:
Configure::write('Config.language', 'fra');
(I've also tried placing it in my AppController's beforeFilter()
which also didn't work)
In my view I have:
<?php
Debugger::dump( Configure::read('Config.language') );
Debugger::dump( CakeSession::read('Config.language') );
echo __('Find a Place');
?>
But when I load the page I just see:
'fra'
null
Find a Place
Why?????!!!!!!
Update 1 @ndm raised some concerns about caching...
In my persistent cache the following files appear:
.../temp/cache/persistent/myapp_cake_core_cake_fra
.../temp/cache/persistent/myapp_cake_core_default_fra
.../temp/cache/persistent/myapp_cake_core_file_map
.../temp/cache/persistent/myapp_cake_core_method_cache
Update 2 Following @ndm's advice, I hacked out everything but one translation in the .po file and it WORKED!
# LANGUAGE translation of CakePHP Application
# Copyright YEAR NAME <EMAIL@ADDRESS>
#
msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"POT-Creation-Date: 2014-11-20 11:30-0500\n"
"PO-Revision-Date: 2014-11-20 11:43-0500\n"
"Last-Translator: SDP\n"
"Language-Team: <EMAIL@ADDRESS>\n"
"Language: fr_CA\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
"X-Generator: Poedit 1.6.10\n"
#: View/Elements/nav--main.ctp:3
#, fuzzy
msgid "Find a Place"
msgstr "Trouver une place"
Clearly something is wrong with my file, but it's weird because it's a brand new file generated by Poedit AND it passes the "Validate" function without problems. It just says that there are lots of entries that aren't translated yet.
The lines I removed from the file look like this:
...
#: Controller/FavoritesController.php:38;73;101
msgid "Invalid favorite"
msgstr ""
#: Controller/FavoritesController.php:53;77
msgid "The favorite has been saved."
msgstr ""
#: Controller/FavoritesController.php:56;80
msgid "The favorite could not be saved. Please, try again."
msgstr ""
...
Anything wrong with that?
app/tmp/cache/persistent
). – ndm.po
file only that contains just one msgid/msgstr pair, check whether there's a locale set in the session (CakeSession::read('Config.language')
) as this will take preceedence (and don't forget the clear cache in between tests :)). – ndmCakeSession
returnsnull
, which I think is correct since I'm not setting it yet... but chopping off all the extra entries in the .po file worked! The one remaining one works! So clearly there is something wrong with the file. But I can't imagine what. It's a brand new file generated from the .pot file that the i18n cake task outputs. Is it a problem that there were many missing entries? I thought was supposed to be fine. Any ideas how to debug the .po file? – emersonthis.po
file only, ie have you deleted the.mo
file? In that case the problem might be that the entry is marked asfuzzy
which should normally cause it to be not compiled into the.mo
file unless this is explicitly asked for (formsgfmt
this would be the-f, --use-fuzzy
option, not sure how poedit compiles the files). That's it for tonight, it's bedtime :) – ndm