How to implement i18n in Cakephp?

Source: Internet
Author: User
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 )!

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.