How to implement i18n in Cakephp?

Source: Internet
Author: User
Tags i18n
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
  1. _ ('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
  1. 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.