cakephp, i18n .po files, How to use them correctly
I have finally managed to set up a multilingual cakephp site. Although not finished it is the first time where I can change the DEFAULT_LANGUAGE in the bootstrap and I can see the language to change.
My problem right now is that I cannot understand very well how to use the po files correctly. According to the tutorials I've used I need to create a folder /app/locale and inside that folder create a folder for each language in the following format: /locale/eng/LC_MESSAGES.
I have done that and I have also managed to extract a default.pot file using cake i18n extract. And it appears that all occurrences of the __() function have been found succesfully.
In my application I'm using 2 languages: eng and gre. I can see why you would need a seperate folder for each language. However in my case nothing happens when I edit the po files inside each folder....well almost nothing. If I edit the /app/locale/gre/LC_MESSAGES/default.po I have no language changes. If I edit the /app/locale/eng/LC_MESSAGES/default.po then the language changes to the new value (on the translation field) and it does not switch to the other language.
What开发者_开发百科 am I doing wrong. I hope I made myself as clear as possible.
There are different ways to go about it. The easiest is to code the app in the primary language and to just wrap all translatable strings in __()
. Later you can add .po
files for each translation you may want.
The problem with this approach is that if you were to change the text in the original language, you'll also need to change the msgid
entry for this string in every .po
file you may have. This can become quite cumbersome if you have to support many different languages.
Please disregard the old information above. A properly set up i18n workflow will use xgettext
or similar utilities to automatically extract __()
wrapped strings from the source code and produce, update and merge .po files. Nothing cumbersome about it.
The alternative is to use a "descriptor" text in the source files and put the actual text in .po
files, even for the primary language. I.e:
__('PRODUCT CAPTION');
/eng/.po
msgid "PRODUCT CAPTION"
msgstr "Buy our awesome products!"
/ger/.po
msgid "PRODUCT CAPTION"
msgstr "Kaufen Sie unsere Produkte!"
What works better depends on the project and on you, you'll have to figure it out...
Use
Configure::write('Config.language', 'fr');
to set the language of the user to french.
精彩评论