Abstract: It seems that no detailed Chinese documents have been provided on the Internet to describe how to use cakephp to implement i18n. Just yesterday, I was forced to show the tips in the code with a little bit of experience, simple and ambitious .... It seems that no detailed Chinese documents have been provided on the Internet to describe how to use cakephp to implement i18n. It was just yesterday that I was forced to show the prompts in the code with a little bit of experience.
Cakephp has the following steps:
1. use the _ () function in the code.
Use the _ () function where the culture is needed, as shown below:
Php code
_ ('This is the string I need to Translate', true );
_ ('This is the string I need to Translate', true );
Set 2nd parameters to true, so that if there is a corresponding translation term, the translated term will be output, otherwise the untranslated term will be output.
2. run the i18n task.
If your code contains the _ () function, you can run the i18n task to scan the code.
I18n task is used to scan all the _ () functions in the source code, create translation indexes for strings in _ (), and save these indexes in the. pot file.
So how to execute i18n tasks?
Run the command line to enter the app directory of your project.
For windows, make sure that the PATH of 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.
Run the command cake i18n. the following prompt appears:
---------------------------------------
I18n Shell
---------------------------------------
[E] xtract POT file from sources
[I] nitialize i18n database table
[H] elp
[Q] uit
What wocould you like to do? (E/I/H/Q)
>
After the i18n task is executed, a file named default. pot should be generated under the \ app \ locale directory, and the file should be copied to the \ app \ locale \ chs \ LC_MESSAGES directory.
Use the pot file editing tool to translate entries. We recommend that you use Poedit.
Add the following code to \ app \ config \ core. php:
Php code
Configure: write ('config. language', 'chs ');
Configure: write ('config. language', 'chs ');
Now, we can complete the cultural aspects of a simple project.
Many of the details are not fully described due to space reasons. If you have any questions, please refer to the help document of cakephp.
The above section describes how to implement i18n in Cakephp. For more information, see PHP Chinese website (www.php1.cn )!