Cakephp internationalization and use of poEdit

Source: Internet
Author: User
Tags i18n
Abstract: Cakephp's powerful i18n function is used for localization and internationalization. By using the language configuration file, the program can adapt to changes for localization. Create a localechiLC_MESSAGESdefault.po file and specify the language option as "chi. This article describes how to implement this localization process... Cakephp's powerful i18n function is used to implement localization and internationalization. By using the language configuration file, the program can adapt to changes for localization. Create a locale/chi/LC_MESSAGES/default. po file and specify the language option as "chi. This article describes how to implement this localization process. of course, poedit in this article is not necessary, but it can make work more efficient.

1. i18n and L10n

The first time I saw these two things, I was confused. However, after a Baidu search, I came to the conclusion that no matter how many n, the ultimate goal is to implement program localization. to put it bluntly, it is a lot of language configuration files, which I understand. You can also go to see, http://baike.baidu.com/view/372835.htm here has a very detailed description.

2. implement localization in Cakephp

So far, there are two configuration methods.

2.1 Method 1

Use configure: write in config/core. php to create a language file.
Configure: write ('config. language', "chi ");

2.2 Method 2

Official description: http://book.cakephp.org/view/162/Localizing-Your-Application
It seems complicated.

App: import ('core', 'l10n'); classTestsController extendsAppController {$ name = "Tests"; functiontest_function () {$ this-> l10n-> newL10n (); $ this-> L10n-> get ("chi ");.....}} 2.3 what needs to be done after making the above settings changes:

Of course, after modification, you also need to modify the corresponding ctp file,

All direct output strings have no returned values, as shown in the following code:

_ ("English ");

Indirect output string, where the returned result is:

_ ("English", true );

You also need to add a label for the input to make it appear in Chinese.

_ ("English"); echo $ form-> input ('name', array ('label' =>__ ('name', true )));

2.4 The most important step

This file is to be edited, locale/chi/LC_MESSAGES/default. po. The chi in the middle is the flag of the language file. The format of this file is also very simple,

Msgid "Chinese"

Msgstr "Chinese"

This is just a simple repeat.

3. use poedit

Using poedit is not necessary, but it can make the work much easier. Official website is: http://www.poedit.net/
Its main function is to make editing language configuration files more convenient and convenient. Below are some simple instructions for using poedit.

3.1 for the first use, you need to select the UI language for reprinting. please specify the source: the internationalization of Cakephp and the use of poEdit.

The above is the international content of Cakephp and the use of poEdit. For more information, see The 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.