How to implement i18n in cakephp?

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

  • 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.