YIIFramework framework Tutorial: internationalization implementation method, yiiframework_PHP tutorial

Source: Internet
Author: User
YIIFramework is an international implementation method of the yiiframework framework tutorial. YIIFramework framework Tutorial: How to internationalize the yiiframework framework tutorial. This article describes how to internationalize the YIIFramework framework tutorial. For your reference, the YII Framework tutorial is about how to internationalize yiiframework.

This article describes how to internationalize the YII Framework tutorial. We will share this with you for your reference. The details are as follows:

A web application is published on the internet to target global users. Users can access your web applications in every corner of the world. of course, your website and non-harmonious web applications cannot be accessed in a harmonious society.

YII provides international support to make our applications suitable for people in different languages.

Internationalization is a fancy thing. no large website can truly be internationalized. Most websites are designed in different regions for languages that are not familiar. If your applications are relatively small and there are not many things to process, you can make things International.

Internationalization starts from the following aspects:

Region settings

Translation of information text and file resources

Date/Time, currency symbol, and Number format

The classes involved in YII internationalization are under the/yii_dev/yii/framework/i18n Directory:

/Yii_dev/yii/framework/i18n # tree
.
── CChoiceFormat. php
── CDateFormatter. php
├ ── CDbMessageSource. php
── CGettextMessageSource. php
├ ── CLocale. php
├ ── CMessageSource. php
── CNumberFormatter. php
── CPhpMessageSource. php
── Data
│ ── En_us.php
│ ├ ── ....................
│ ├ ── Zh_hk.php
│ ── Zh_mo.php
│ ├ ── Zh. php
│ ── Zh_sg.php
│ ── Zh_tw.php
│ ── Zu. php
│ └ ── Zu_za.php
── Gettext
── CGettextFile. php
── CGettextMoFile. php
── CGettextPoFile. php

2 directories, 616 files

Region settings

You can set the region to determine the international and language of your use.

YII defines a common region ID, which can be considered to be the unique ID of the region.

YII stores region data (including currency, date, numeric format, and so on) through the CLocale class ).

You can use CLocale: getInstance ($ localeID) or CApplication: getLocale ($ localeID) to obtain the corresponding CLocale instance. The CLocale instance can be used to determine the country in which the user is located and the language used. Then, you can perform corresponding translation based on CLocale data to make the web application more suitable for use and reading by the current user. The most fundamental thing is to make specific translations for users.

Translation of information text and file resources

Translation is simply to convert one language into another. In the computer, 26 letters are used, that is, e. Therefore, e can be regarded as the source language and the source language of HiChina. All other languages are translated by e. For the moment, e is called the source language. The translated language is called the target language.

Specific class description

/*** Translates a message to the specified language.* Starting from version 1.0.2, this method supports choice format (see {@link CChoiceFormat}),* i.e., the message returned will be chosen from a few candidates according to the given* number value. This feature is mainly used to solve plural format issue in case* a message has different plural forms in some languages.* @param string $category message category. Please use only word letters. Note, category 'yii' is* reserved for Yii framework core code use. See {@link CPhpMessageSource} for* more interpretation about message category.* @param string $message the original message* @param array $params parameters to be applied to the message using strtr.* Starting from version 1.0.2, the first parameter can be a number without key.* And in this case, the method will call {@link CChoiceFormat::format} to choose* an appropriate message translation.* Starting from version 1.1.6 you can pass parameter for {@link CChoiceFormat::format}* or plural forms format without wrapping it with array.* @param string $source which message source application component to use.* Defaults to null, meaning using 'coreMessages' for messages belonging to* the 'yii' category and using 'messages' for the rest messages.* @param string $language the target language. If null (default), the {@link CApplication::getLanguage application language} will be used.* This parameter has been available since version 1.0.3.* @return string the translated message* @see CMessageSource*/public static function t($category,$message,$params=array(),$source=null,$language=null){

$ Category source language
$ Mesage target language
$ Params is an array in $ mesage that matches the translation.

The specific usage is as follows:

Yii::t('app', 'Path alias "{alias}" is redefined.',  array('{alias}'=>$alias))

Of course, you can use the command line command message provided by yiic for translation. for details, refer to the instructions for using yiic commands.

Date/Time, money, and Number format

Date/Time processing CDateFormatter class
For more information, see (/yii_dev/yii/framework/i18n/CDateFormatter. php ).

Digital processing
For more information, see (/yii_dev/yii/framework/i18n/CNumberFormatter. php ).

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.