internationalization and localization in cakephp

I18n and l11n in cakephp is extremely easy. However before we start, you need to download and install a po file editor. The one I use is called poedit.
The main thing you need to change in your application is the way you handle your string constants. Normally, you just type out phrases in your application like:

$site_title = "My site title";

To internationalize it, you change it to

$site_title = __("My site title",true);

The __ function takes a string and returns or echoes the localized version of it by checking the language files. The second parameter tells it if the localized string should be returned.
Obviously, if you are outputting string in your view file. You don’t need the second parameter because it defaults to false.
Now that your files are ready to be localized, you can start creating the language files you desire.
1. create a folder in app/locale with an appropriate name like rus for russian and eng for english
2. create a folder called LC_MESSAGES. This folder will contain the actual language file.
Now we need to configure the po editor you downloaded earlier.
1. download and install it, of course.
2. now close the catalog manager. go File->Preference
3. go to translation memory tab, set max.# of missing words to 0 and max. difference in sentence length to 0
4. go to parsers tab, add a new source code parser called php if one doesn’t already exist.
5. in php parser’s setting window, change the list of extentions to *.ctp;*.php, add whatever suits your needs.
6. change parse command to xgettext –force-po -o %o %C %K %F –language=php
7. change an item in keywords list to -k%k
8. change an item in input files list to %f
9. source code charset to –from-code=%c and now hit ok to save everything
10. open poedit, go to File->Catalogs Manager
11. click on the create a new translation project.
12. give it a name and set the directory to you projects app folder. in my case it looks something like this D:\htdocs\web\public\mysite\app\
13. Now go to File->New Catalog…
14. give it a name, set charset to UTF-8
15. go to paths tab, here you add folders that you want poedit to scan through to look for files. With cakephp the folders you want to include are the controller folder and view folders. you need to enter each of them separetly as poedit don’t go through the folders recursively.
in my case i added


The last dot tells it to look in app folder for files like app_controller.php
16. go to keywords tab, add __ as a keywords. This tells poedit to look for __ when search through the files in path tab. hit ok to save.
17. with a little luck and all the stuff set correctly. you can hit the update catalog button and you should see your string constants in poedit and click on one to write the translation for it.
With all these you still need to tell cakephp which language to use. you can do that like


You can send this file to your client and he can use poedit to update the file and send it back to you. All you have to do is to put the file in the appropriate folder in locale, open it with poedit and hit the update button. Then you are set. Pretty frigging awsome if you ask me.