2. What is Localization ?
It is the process of making your applications or
websites local to where it is being viewed. For
example, you can make a website more local to a
particular place by converting its text to the
predominate language of that location and by
displaying the local time
3. Wrapping Translatable Text in __()
Functions
Supposing our menu looked like the following:
<ul>
<li>Send</li>
<li>Reply</li>
</ul>
We would wrap each text string inside the __() function
like as follows:
<ul>
<li><?php echo __('Send') ?></li>
<li><?php echo __('Reply') ?></li>
</ul>
4. ● The __() function identifies these strings as
translatable text that will differ by language locale and
uses the text within the __() function as the message
ID. If we define the translations for a certain language,
those translations will appear in place of these
functions. If we do not define the translations for that
language, the text within the __() function will display
instead by default.
5. Creating the Localized PO Files
● The next step is to create the PO files which will contain
the translations for each language to be dynamically
inserted in each of the __() functions. CakePHP has two
ways you can do this: automatically using the console
shell; or manually.
Using the I18N Shell
CakePHP has some console shell programs that you can
run on the command line, including one to generate the PO
file to use as the original language source file for
translations. In our case it will be a file with all the English
text strings.
6. Creating the Localized PO Files
● To run the i18n shell command, type the following on the Linux
command line in your CakePHP application directory:
./Console/cake i18n extract
Then follow the onscreen menu.
The shell command will examine all of your application files
for instances of the __() function and generate a PO file for the
original source language that you can use to create the PO files
for each of the translations you are going to use.
7. Creating the PO Files Manually
● If you want to do this manually—for example you
don’t have many translatable text strings like in our
example—you can create the PO files by hand in a text
editor.
● First we will create the original source language
English version here:
● /app/Locale/eng/LC_MESSAGES/default.po
● The default.po file will have this format:
● msgid "ID"
● msgstr "STRING"
8. Creating the PO Files Manually
● Where msgid is the ID within the __() function; msgstr
is the localized translation that should appear as
output.
● Our full English source PO file will look like this:
msgid "Send"
msgstr "Send"
msgid "Reply"
msgstr "Reply"
9. Creating the PO Files Manually
● To create the Japanese localized version, we copy the
English PO file to the Japanese directory, and then
replace the English strings in the msgstr field with the
Japanese translations. (If you have a large application
being localized into dozens of languages, it is at this
point that you send the PO files to a language service
provider to translate the localized strings.)
● Our localized PO file with Japanese translations will
go here:
/app/Locale/jpn/LC_MESSAGES/default.po
10. Creating the PO Files Manually
● Our final localized Japanese PO file will look like this.
msgid "Send"
msgstr " 送信 "
msgid "Reply"
msgstr " 返信 "
● That’s it. The translations for English and Japanese will
display appropriately for the proper locale. If you want to
add translations for other languages, you do the same
process and put the new PO file in the directory that
corresponds with that language code.
11. Creating the PO Files Manually
● Our final localized Japanese PO file will look like this.
msgid "Send"
msgstr " 送信 "
msgid "Reply"
msgstr " 返信 "
● That’s it. The translations for English and Japanese will
display appropriately for the proper locale. If you want to
add translations for other languages, you do the same
process and put the new PO file in the directory that
corresponds with that language code.
12. ● In your app Controller, inside before filter you need to
configure the language based on the region, It will be
as follows , Here am considering the japan as a
language . So based on the
● Configure::write('Config.language', 'jpn');