It seems that there has been no more detailed Chinese information on how to use cakephp to implement i18n. Just yesterday was forced to helpless the code in the hint of a culture, a little experience, Jane and Zhi.
The Chinese culture cakephp has the following steps:
1, use the __ () function in your code.
Use the __ () function where you need to be in culture, as follows:
PHP code
__ (' This was the string I need to translate ', true);
__ (' This was the string I need to translate ', true);
Set the 2nd parameter to ture so that if there is a corresponding translation entry then the translated entry will be output, otherwise the untranslated entry will be output.
2, execute i18n task
If you have the __ () function in your code, you can execute the I18N task to scan the code.
The role of the i18n task is to scan all __ () functions in the source code, create a translation index for the string in __ (), and save the indexes in a. pot file.
So how do you execute i18n task?
command line access to your project's app directory
If you are a Windows platform, make sure that the path to the environment variable contains the bin path of PHP and that the cake\console in your cake directory also exists in the path of the environment variable
Execute the command cake i18n, this time should appear the following prompt, select E can either
---------------------------------------
i18n Shell
---------------------------------------
[E]xtract POT file from sources
[I]nitialize i18n database table
[H]elp
[Q]uit
What would? (e/i/h/q)
>
After the i18n task executes, you should generate a file named Default.pot in the \app\locale directory and copy the file to the \app\locale\chs\lc_messages directory.
Use the pot file's editing tools to translate the entry. Recommended use of Poedit
Add the following code to the \app\config\core.php:
PHP code
Configure::write (' config.language ', ' CHS ');
Configure::write (' config.language ', ' CHS ');
Well, this completes the simple culture of the project.
Many of these details are not fully introduced because of their length. If you have any questions, please refer to CakePHP's help documentation.
The above is how cakephp implement i18n content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!