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.
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. if it is a windows platform, make sure that the PATH of the environment variable contains the php bin PATH, make sure that the cake \ console in your cake directory also exists in the PATH of the environment variable and execute the command cake i18n. in this case, the following prompt appears:
---------------------------------------I18n Shell---------------------------------------[E]xtract POT file from sources[I]nitialize i18n database table[H]elp[Q]uitWhat would you like to do? (E/I/H/Q)>
After the i18n task is executed, the default name should be generated under the \ app \ locale directory. copy the pot file to the \ app \ locale \ chs \ LC_MESSAGES directory and use the pot file editing tool to translate the entries. We recommend that you use Poedit to add the following code in \ 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.