Cakephp's powerful i18n function is used for localization and internationalization. By using the language configuration file, the program can adapt to changes for localization. Create a locale/chi/LC_MESSAGES/default. po file and specify the language option as "chi. This article describes how to implement the localization process.
Cakephp's powerful i18n function is used for localization and internationalization. By using the language configuration file, the program can adapt to changes for localization. Create a locale/chi/LC_MESSAGES/default. po file and specify the language option as "chi. This article describes how to implement this localization process. of course, poedit in this article is not necessary, but it can make work more efficient.
1. i18n and L10n
The first time I saw these two things, I was confused. However, after a Baidu search, I came to the conclusion that no matter how many n, the ultimate goal is to implement program localization. to put it bluntly, it is a lot of language configuration files, which I understand. You can also go to see, http://baike.baidu.com/view/372835.htm here has a very detailed description.
2. implement localization in Cakephp
So far, there are two configuration methods.
2.1 Method 1
Use configure: write in config/core. php to create a language file.
Configure: write ('config. language', "chi ");
2.2 Method 2
Official description: http://book.cakephp.org/view/162/Localizing-Your-Application
It seems complicated.
App: import ('core', 'l10n'); classTestsController extendsAppController {$ name = "Tests"; functiontest_function () {$ this-> l10n-> newL10n (); $ this-> L10n-> get ("chi ");.....}} 2.3 what needs to be done after making the above settings changes:
Of course, after modification, you also need to modify the corresponding ctp file,
All direct output strings have no returned values, as shown in the following code:
_ ("English ");
Indirect output string, where the returned result is:
_ ("English", true );
You also need to add a label for the input to make it appear in Chinese.
_ ("English"); echo $ form-> input ('name', array ('label' =>__ ('name', true )));
2.4 The most important step
This file is to be edited, 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,
Msgid "Chinese"
Msgstr "Chinese"
This is just a simple repeat.
3. use poedit
Using poedit is not necessary, but it can make the work much easier. Official website is: http://www.poedit.net/
Its main function is to make editing language configuration files more convenient and convenient. Below are some simple instructions for using poedit.
3.1 select the interface language for the first use