Multilingual Website with CakePHP

We all know that developing a website in CakePHP is very easy and also fast. Here’s how to create a multilingual website fast.
First open app/config/bootstrap.php and set the languages you want available for your website:

Configure::write('Config.languages', array(
'ro' => array(
'language' => 'Romanian',
'locale' => 'rum',
'localeFallback' => 'rum',
'charset' => 'utf-8'
),
'en' => array(
'language' => 'English',
'locale' => 'eng',
'localeFallback' => 'eng',
'charset' => 'utf-8'
),
)
);

I chose english and romanian for this example.
Now open your app controller (app/app_controller.php – create one if you don’t have it) and put this function in it:

function setLanguage() {
if(!isset($this->params['lang'])) $this->params['lang'] = 'ro';
$lang = $this->params['lang'];
App::import('Core', 'i18n');
$I18n =& I18n::getInstance();
$I18n->l10n->get($lang);
foreach (Configure::read('Config.languages') as $lang => $locale) {
if($lang == $this->params['lang'])
$this->params['locale'] = $locale['locale'];
}
}

All you have to modify in this function is the first line (that sets the default language). Change the default language to your chosen one.
It’s now time to create a route depending on the language. Open app/config/routes.php and add this route to it:

Router::connect('/:lang/:controller/:action/*', array('lang' => 'ro'), array('lang' => 'ro|en'));

Of course that this can change depending on the languages you are using and their number. You’re a smart boy so you’ll figure it out.
Now all you have left is to create the language files. Go to app/locale and create 2 folders: rum and en. In each of these folders create another folder called LC_MESSAGES. In the LC_MESSAGES folders you will now store the language files. Language files can be divided so it’s easier for you to store the translations ( .po files ).
For example, you can create a login.po, register.po, account.po and default.po.
In the language files you have to set the message id and message string.
English

msgid "hello"
msgstr "Hello"

Romanian

msgid "hello"
msgstr "Buna ziua"

And now to echo these strings on your website you have to remember the string id and the name of the language file (.po) it is stored in. Example:

<?
__d('default', 'hello', true);
?>

This will take the string with the id “hello” from the default.po file and echo it. And true means that it will echo the string.
Good luck