Home > General Cakephp > i18n and l10n in cakephp

i18n and l10n in cakephp

August 18th, 2009

In order to add I18n and l10n into Jqcms, I have been searching internet to implement this feature.

And this is my final solution of I18n and l10n in cakephp .

Please note my current cakephp version is 1.2.1 .

1.Create your locale file.
The file path is app/locale/eng/LC_MESSAGES/default.po.
You could create your customized locale file such as  app/locale/fre/LC_MESSAGES/default.po.
app/locale/rus/LC_MESSAGES/default.po.

whereas, default.po is the actually locale file which contains the content.
It is recommanded to use po edit to edit this locale file due to its encoding.
However, when I used notepad to edit it, it works still fine.
The content of the file looks like this:

</code></code></code>

msgid   "add"
msgstr "Add Content"

<code>

msgid is the id of the string , msgstr is the string content. You could create as many pairs as you need.

2.Initialize your locale

To tell cakephp which locale you want to use, or change current locale file. I did this in my controller:

</code>
$this->Session->write('Config.language','en');
<code>

However, I found out that doing this is fine too

</code>
Configure::write('Config.language','rus');
<code>

3.View your locale String

After two simple steps above, now you can make use of it by doing :

</code>
__("add")
<code>

Please note it is a double underscore __ instead of single underscore _

If you wish to use po editor create or edit your locale file, refer to

http://www.bunchacode.com/programming/internationalization-and-localization-in-cakephp/

Thanks for reading.

Please comment if you have any problem or I have made any mistakes.

admin General Cakephp , , ,

  1. No comments yet.
  1. No trackbacks yet.
Security Code:

Get Adobe Flash playerPlugin by wpburn.com wordpress themes