際際滷

際際滷Share a Scribd company logo
Localizing a CakePHP Application
Presented By
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
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>
¢ 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.
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.
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.
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"
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"
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
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.
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.
¢ 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');
Ad

Recommended

Glance rebol
Glance rebol
crazyaxe
?
Php
Php
rida mariam
?
C language 1
C language 1
cprogram
?
All the language support in Drupal 8 - At Drupalaton 2014
All the language support in Drupal 8 - At Drupalaton 2014
G│bor Hojtsy
?
果僥閘 Rebol只霧
果僥閘 Rebol只霧
d0nn9n
?
single pass compiler and its architecture
single pass compiler and its architecture
noor ul ain
?
Php
Php
merlin deepika
?
Php
Php
Yuvaraja Rajenderan
?
Php1
Php1
rajikaa
?
Rebol brainwasher
Rebol brainwasher
crazyaxe
?
Plone i18n, LinguaPlone
Plone i18n, LinguaPlone
Quintagroup
?
Php Vs Phyton
Php Vs Phyton
Francis Guison
?
topic_perlcgi
topic_perlcgi
tutorialsruby
?
Bottom-Line Web Services
Bottom-Line Web Services
Mohammed Makhlouf
?
Python Intro For Managers
Python Intro For Managers
Atul Shridhar
?
Ruby, Meet iPhone
Ruby, Meet iPhone
Atomic Object
?
PHP to Python with No Regrets
PHP to Python with No Regrets
Alex Ezell
?
Introduction to php
Introduction to php
Suraj Motee
?
ALPHA Script - Concept
ALPHA Script - Concept
PROBOTEK
?
Lets Go - An introduction to Google's Go Programming Language
Lets Go - An introduction to Google's Go Programming Language
Ganesh Samarthyam
?
Client side scripting
Client side scripting
Eleonora Ciceri
?
C introduction
C introduction
Kamran
?
Jaws User Group in Ehime Lightning Talk
Jaws User Group in Ehime Lightning Talk
Kazuaki Ueda
?
Making bootable usb of ESXi-5.0
Making bootable usb of ESXi-5.0
Kazuaki Ueda
?
Android api-levels
Android api-levels
Kazuaki Ueda
?
Bidifydeb
Bidifydeb
debshenefield
?
いろいろCMS茶氏 featuring SHIRASAGI
いろいろCMS茶氏 featuring SHIRASAGI
Kazuaki Ueda
?
Ci tutorial
Ci tutorial
Kazuaki Ueda
?
邦袗デザイン柮 猟忖モジ氏
邦袗デザイン柮 猟忖モジ氏
Kazuaki Ueda
?
Esxi client-4to5
Esxi client-4to5
Kazuaki Ueda
?

More Related Content

What's hot (14)

Php1
Php1
rajikaa
?
Rebol brainwasher
Rebol brainwasher
crazyaxe
?
Plone i18n, LinguaPlone
Plone i18n, LinguaPlone
Quintagroup
?
Php Vs Phyton
Php Vs Phyton
Francis Guison
?
topic_perlcgi
topic_perlcgi
tutorialsruby
?
Bottom-Line Web Services
Bottom-Line Web Services
Mohammed Makhlouf
?
Python Intro For Managers
Python Intro For Managers
Atul Shridhar
?
Ruby, Meet iPhone
Ruby, Meet iPhone
Atomic Object
?
PHP to Python with No Regrets
PHP to Python with No Regrets
Alex Ezell
?
Introduction to php
Introduction to php
Suraj Motee
?
ALPHA Script - Concept
ALPHA Script - Concept
PROBOTEK
?
Lets Go - An introduction to Google's Go Programming Language
Lets Go - An introduction to Google's Go Programming Language
Ganesh Samarthyam
?
Client side scripting
Client side scripting
Eleonora Ciceri
?
C introduction
C introduction
Kamran
?
Rebol brainwasher
Rebol brainwasher
crazyaxe
?
Plone i18n, LinguaPlone
Plone i18n, LinguaPlone
Quintagroup
?
Python Intro For Managers
Python Intro For Managers
Atul Shridhar
?
PHP to Python with No Regrets
PHP to Python with No Regrets
Alex Ezell
?
Introduction to php
Introduction to php
Suraj Motee
?
ALPHA Script - Concept
ALPHA Script - Concept
PROBOTEK
?
Lets Go - An introduction to Google's Go Programming Language
Lets Go - An introduction to Google's Go Programming Language
Ganesh Samarthyam
?
C introduction
C introduction
Kamran
?

Viewers also liked (19)

Jaws User Group in Ehime Lightning Talk
Jaws User Group in Ehime Lightning Talk
Kazuaki Ueda
?
Making bootable usb of ESXi-5.0
Making bootable usb of ESXi-5.0
Kazuaki Ueda
?
Android api-levels
Android api-levels
Kazuaki Ueda
?
Bidifydeb
Bidifydeb
debshenefield
?
いろいろCMS茶氏 featuring SHIRASAGI
いろいろCMS茶氏 featuring SHIRASAGI
Kazuaki Ueda
?
Ci tutorial
Ci tutorial
Kazuaki Ueda
?
邦袗デザイン柮 猟忖モジ氏
邦袗デザイン柮 猟忖モジ氏
Kazuaki Ueda
?
Esxi client-4to5
Esxi client-4to5
Kazuaki Ueda
?
Android multiscreen
Android multiscreen
Kazuaki Ueda
?
Making bootable USB by update from 4.1 to 5.0
Making bootable USB by update from 4.1 to 5.0
Kazuaki Ueda
?
Android test tutorial
Android test tutorial
Kazuaki Ueda
?
Pembelajaran berasaskan projek
Pembelajaran berasaskan projek
Hailmi Othman
?
Cms festa-0216
Cms festa-0216
Kazuaki Ueda
?
Android Develop presentation on 19 Sep 2012.
Android Develop presentation on 19 Sep 2012.
Kazuaki Ueda
?
Sudachi hackathon
Sudachi hackathon
Kazuaki Ueda
?
Android studio で佩ってみよう。
Android studio で佩ってみよう。
Kazuaki Ueda
?
Modul edu3105
Modul edu3105
Hailmi Othman
?
Chalo Dilli
Chalo Dilli
dilsegao
?
Kemahiran proses sains
Kemahiran proses sains
Hailmi Othman
?
Jaws User Group in Ehime Lightning Talk
Jaws User Group in Ehime Lightning Talk
Kazuaki Ueda
?
Making bootable usb of ESXi-5.0
Making bootable usb of ESXi-5.0
Kazuaki Ueda
?
いろいろCMS茶氏 featuring SHIRASAGI
いろいろCMS茶氏 featuring SHIRASAGI
Kazuaki Ueda
?
邦袗デザイン柮 猟忖モジ氏
邦袗デザイン柮 猟忖モジ氏
Kazuaki Ueda
?
Making bootable USB by update from 4.1 to 5.0
Making bootable USB by update from 4.1 to 5.0
Kazuaki Ueda
?
Android test tutorial
Android test tutorial
Kazuaki Ueda
?
Pembelajaran berasaskan projek
Pembelajaran berasaskan projek
Hailmi Othman
?
Android Develop presentation on 19 Sep 2012.
Android Develop presentation on 19 Sep 2012.
Kazuaki Ueda
?
Android studio で佩ってみよう。
Android studio で佩ってみよう。
Kazuaki Ueda
?
Kemahiran proses sains
Kemahiran proses sains
Hailmi Othman
?
Ad

Recently uploaded (20)

"How to survive Black Friday: preparing e-commerce for a peak season", Yurii ...
"How to survive Black Friday: preparing e-commerce for a peak season", Yurii ...
Fwdays
?
Tech-ASan: Two-stage check for Address Sanitizer - Yixuan Cao.pdf
Tech-ASan: Two-stage check for Address Sanitizer - Yixuan Cao.pdf
caoyixuan2019
?
Daily Lesson Log MATATAG ICT TEchnology 8
Daily Lesson Log MATATAG ICT TEchnology 8
LOIDAALMAZAN3
?
The Future of Product Management in AI ERA.pdf
The Future of Product Management in AI ERA.pdf
Alyona Owens
?
Techniques for Automatic Device Identification and Network Assignment.pdf
Techniques for Automatic Device Identification and Network Assignment.pdf
Priyanka Aash
?
OWASP Barcelona 2025 Threat Model Library
OWASP Barcelona 2025 Threat Model Library
PetraVukmirovic
?
Enhance GitHub Copilot using MCP - Enterprise version.pdf
Enhance GitHub Copilot using MCP - Enterprise version.pdf
Nilesh Gule
?
Lessons Learned from Developing Secure AI Workflows.pdf
Lessons Learned from Developing Secure AI Workflows.pdf
Priyanka Aash
?
UserCon Belgium: Honey, VMware increased my bill
UserCon Belgium: Honey, VMware increased my bill
stijn40
?
OpenPOWER Foundation & Open-Source Core Innovations
OpenPOWER Foundation & Open-Source Core Innovations
IBM
?
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
pcprocore
?
Quantum AI Discoveries: Fractal Patterns Consciousness and Cyclical Universes
Quantum AI Discoveries: Fractal Patterns Consciousness and Cyclical Universes
Saikat Basu
?
Cyber Defense Matrix Workshop - RSA Conference
Cyber Defense Matrix Workshop - RSA Conference
Priyanka Aash
?
Curietech AI in action - Accelerate MuleSoft development
Curietech AI in action - Accelerate MuleSoft development
shyamraj55
?
Using the SQLExecutor for Data Quality Management: aka One man's love for the...
Using the SQLExecutor for Data Quality Management: aka One man's love for the...
Safe Software
?
2025_06_18 - OpenMetadata Community Meeting.pdf
2025_06_18 - OpenMetadata Community Meeting.pdf
OpenMetadata
?
Oh, the Possibilities - Balancing Innovation and Risk with Generative AI.pdf
Oh, the Possibilities - Balancing Innovation and Risk with Generative AI.pdf
Priyanka Aash
?
Security Tips for Enterprise Azure Solutions
Security Tips for Enterprise Azure Solutions
Michele Leroux Bustamante
?
Smarter Aviation Data Management: Lessons from Swedavia Airports and Sweco
Smarter Aviation Data Management: Lessons from Swedavia Airports and Sweco
Safe Software
?
Securing AI - There Is No Try, Only Do!.pdf
Securing AI - There Is No Try, Only Do!.pdf
Priyanka Aash
?
"How to survive Black Friday: preparing e-commerce for a peak season", Yurii ...
"How to survive Black Friday: preparing e-commerce for a peak season", Yurii ...
Fwdays
?
Tech-ASan: Two-stage check for Address Sanitizer - Yixuan Cao.pdf
Tech-ASan: Two-stage check for Address Sanitizer - Yixuan Cao.pdf
caoyixuan2019
?
Daily Lesson Log MATATAG ICT TEchnology 8
Daily Lesson Log MATATAG ICT TEchnology 8
LOIDAALMAZAN3
?
The Future of Product Management in AI ERA.pdf
The Future of Product Management in AI ERA.pdf
Alyona Owens
?
Techniques for Automatic Device Identification and Network Assignment.pdf
Techniques for Automatic Device Identification and Network Assignment.pdf
Priyanka Aash
?
OWASP Barcelona 2025 Threat Model Library
OWASP Barcelona 2025 Threat Model Library
PetraVukmirovic
?
Enhance GitHub Copilot using MCP - Enterprise version.pdf
Enhance GitHub Copilot using MCP - Enterprise version.pdf
Nilesh Gule
?
Lessons Learned from Developing Secure AI Workflows.pdf
Lessons Learned from Developing Secure AI Workflows.pdf
Priyanka Aash
?
UserCon Belgium: Honey, VMware increased my bill
UserCon Belgium: Honey, VMware increased my bill
stijn40
?
OpenPOWER Foundation & Open-Source Core Innovations
OpenPOWER Foundation & Open-Source Core Innovations
IBM
?
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
pcprocore
?
Quantum AI Discoveries: Fractal Patterns Consciousness and Cyclical Universes
Quantum AI Discoveries: Fractal Patterns Consciousness and Cyclical Universes
Saikat Basu
?
Cyber Defense Matrix Workshop - RSA Conference
Cyber Defense Matrix Workshop - RSA Conference
Priyanka Aash
?
Curietech AI in action - Accelerate MuleSoft development
Curietech AI in action - Accelerate MuleSoft development
shyamraj55
?
Using the SQLExecutor for Data Quality Management: aka One man's love for the...
Using the SQLExecutor for Data Quality Management: aka One man's love for the...
Safe Software
?
2025_06_18 - OpenMetadata Community Meeting.pdf
2025_06_18 - OpenMetadata Community Meeting.pdf
OpenMetadata
?
Oh, the Possibilities - Balancing Innovation and Risk with Generative AI.pdf
Oh, the Possibilities - Balancing Innovation and Risk with Generative AI.pdf
Priyanka Aash
?
Smarter Aviation Data Management: Lessons from Swedavia Airports and Sweco
Smarter Aviation Data Management: Lessons from Swedavia Airports and Sweco
Safe Software
?
Securing AI - There Is No Try, Only Do!.pdf
Securing AI - There Is No Try, Only Do!.pdf
Priyanka Aash
?
Ad

Localization

  • 1. Localizing a CakePHP Application Presented By
  • 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');