This is simple, but if you never did it some suggestion may help.
Internationalization and localization of the static text in a cakephp application is fast and easy, as explained in the book.
One fact that was not actually clear to me is, adding new string and updating an alredy existent transaltion is also a breeze.
Thanks to the i18n console task and poEdit.
As the cookbook says, just wrap every text in the __() function to internationalize.
Note that: __(‘default text if no translation is found’) will echo the string, while __(‘string to return’, true) will return the string. Always set the second parameter totrue iwhen you use the function inside other functions ($html->link() being the first that comes into mind).
If you see some text where it shouldn’t be, chances are you forgot the second parameter.
For modularity, another useful function is __d(). It has a third parameter, setting the domain, so we can have differnet .po files for differnet plugins, themes, modules..
Well, all this is quite obvious if yuo take the time to read the cookbook. Once you ave your interface internationalized, with every string wrapped with the function, it’s time to get ready for the translation.
In the shell / command promt, it’s ust a matter of calling cake i18n. And then choose the ‘E’ option and hitting enter (the dafault are fine). This recursively parses the files of your project and extracts the strings. It then creates the default.pot (and, if some __d() is present, the variuos domain_name.pot).
Just copy it in your language folder (i.e. app/locale/ita/LC_MESSAGES). You can start editing it with your IDe / editor of choice, adding translations, but.. wait. Here comes poEdit. Use it: it forces standards, handles quotes and other potential formatting prblems and much more.
The main benefit I found is in adding new translations.
What if you change some view, add other text to translate, and delete some? The cakep i18n shell command overwrites the original pot files. Manually Synching this with the translated one is a pain.
With poEdit it is a breeze.
Open your out of date translated pot file (i.e locale/ita/LC_MESSAGES/default.pot):
menu Catalog -> update form .pot file. poEdit will check the changes, remove the original string no longer available in the new pot file and andd the new ones, ready for translation.
Tranlate, save upload. Done.
Wasn’t it easy?