The internationalization of cakephp and the use of Poedit

Source: Internet
Author: User
Tags i18n
CakePHP's powerful i18n feature is for localization and internationalization. By using a language profile, he allows the program to adapt well to changes and localize. By creating a new Locale/chi/lc_messages/default.po file, and specifying the language option for "Chi" implementation. This article is about how to achieve this localization process, of course, the poedit in this article is not necessary, but he can make more efficient.

I. About I18N and L10N

These 2 things actually the first time I see the time is also confused, but after a search Baidu, came to the conclusion that no matter how many N, the ultimate goal is to realize the program localization is good, plainly, is by a lot of language configuration file, anyway I understand. You can also go to see, http://baike.baidu.com/view/372835.htm here is a very detailed explanation.

Second, in CakePHP, the way to achieve localization

So far, there are 2 configuration methods.

2.1 Method One

Use Configure::write in config/core.php to develop language files.
Configure::write (' Config.language ', "Chi");

2.2 Method Two

Official Note: http://book.cakephp.org/view/162/Localizing-Your-Application
It seems very complicated to say oh.

App::import (' Core ', ' l10n '); Classtestscontroller extendsappcontroller{$name = "Tests"; Functiontest_function () {$this->l10n->newl10n (); $ This->l10n->get ("Chi"); ..... } }2.3 do what you need to do to make the above settings changes:

Of course, in the above modifications, you also need to modify the corresponding CTP files, etc. oh,

All the direct output strings, no return values are places like this:

__ ("中文版");

The indirect output string, where there is a return:

__ ("中文版", true);

and input to add a label to make him appear in Chinese.

__ ("中文版"); Echo $form->input (' name ', Array (' label ' =>__ (' name ', true));

2.4 The most important step

is to edit this file, Locale/chi/lc_messages/default.po. The middle Chi is the symbol of the language file. The format of this file is also very simple,

MsgId "Chinese"

Msgstr "Chinese Language"

The simple repetition of this is all right.

Third, the use of Poedit

Using Poedit is not necessary, but it can make the job much easier. The official website is: http://www.poedit.net/
His main function is to make editing language configuration files more convenient and fast. Here are some simple and illustrative uses of Poedit.

3.1 First time use need to select the interface language reprint please specify the Source: CakePHP's internationalization and poedit use

The above is CakePHP's internationalization and poedit use of 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.