Home>Article>Backend Development> Internationalization of Cakephp and use of poEdit
Cakephp’s very powerful i18n function is used to achieve localization and internationalization. It uses language configuration files to enable programs to adapt to changes and be localized. Implement this by creating a new locale/chi/LC_MESSAGES/default.po file and specifying the language option as "chi". This article talks about how to implement this localization process. Of course, poetry in this article is not necessary, but it can make work more efficient.
1. About i18n and L10n
In fact, I was confused when I saw these two things for the first time, but after a search on Baidu, I came to the conclusion that no matter how many n, the ultimate goal Just implement program localization. To put it bluntly, it consists of many language configuration files. Anyway, this is how I understand it. You can also take a look at http://baike.baidu.com/view/372835.htm There are very detailed instructions here.
2. How to implement localization in Cakephp
So far, there are 2 configuration methods.
2.1 Method 1
Use configure::write in config/core.php to specify the language file.
Configure::write('Config.language',"chi");
2.2 Method 2
Official description: http://book.cakephp.org/view/162/Localizing-Your-Application
It seems very complicated Say oh.
App::import('Core', 'l10n'); classTestsController extendsAppController{ $name="Tests"; functiontest_function(){ $this->L10n->newL10n(); $this->L10n- >get("chi"); ..... } }2.3 What you need to do after making the above settings changes:
Of course, after making the above changes, you also need to modify the corresponding ctp file, etc.
All directly Output a string, where there is no return value like this:
__("english");
Output the string indirectly, where there is a return:
__("english",true);
There is also input required Add a label to make it appear in Chinese.
__("english");echo $form->input('name',array('label'=>__('name',true))));
2.4 The most important step
Just edit this file, locale/chi/LC_MESSAGES/default.po. The chi in the middle is the flag of the language file. The format of this file is also very simple, just a simple repetition of
msgid "Chinese"
msgstr "中文"
will do.
3. Use poedit
Using poedit is not necessary, but it can make the work much easier. The official website is: http://www.poedit.net/
Its main function is to make editing language configuration files more convenient and faster. Below are some simple screenshots and instructions for using poetry.
3.1 You need to select the interface language for the first time. Please indicate the source for reprinting: Internationalization of Cakephp and the use of poEdit
The above is the content of the internationalization of Cakephp and the use of poEdit. For more related content, please pay attention to the PHP Chinese website (www .php.cn)!