The internationalization implementation method of YII framework frame Tutorial _php Example

Source: Internet
Author: User
Tags i18n unique id smarty template yii

This article describes the internationalization implementation of the YII framework tutorial. Share to everyone for your reference, specific as follows:

A Web application, published to the Internet, is intended for global users. Users in all corners of the world can access to your Web applications, of course, to see your site and disharmony, the disharmony of the Web application in a harmonious society is not let you visit.

Yii provides internationalization support that allows us to create applications that are suitable for people of different languages.

Internationalization is a very fancy thing, no big website can truly internationalization. Most of them are for the language not understand, different regions design different sites. If your application is relatively small, there are not many things to deal with, then the internationalization of things is quite ok.

Internationalization starts with the following aspects:

Regional Settings

Translation of information texts and document resources

Date/time, currency symbol, and number format

The classes involved in the internationalization of Yii 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

Regional Settings

Determine the international and used language of the user by setting up the locale.

Yii defines a common area identity, which can be considered a unique ID that represents a zone.

Yii stores area data (including currency, date, number format, and so on) through the Clocale class.

The corresponding Clocale instance can be obtained by clocale::getinstance ($localeID) or Capplication::getlocale ($localeID) through a zone unique ID. By Clocale instance, you can judge the language of the user's country. It can then be translated according to the Clocale data, making the Web application more suitable for the current user to use and read. The most fundamental is to make a specific translation for the user.

Translation of information texts and document resources

It is easy to translate a language into another language. In the computer is 26 letters, that is, e-text. So you can take e as the original language, million language source, all the other languages are translated through e-text, 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 (check {@link Cchoiceformat}), * i.e., the message Returne D'll be chosen from a few candidates according to the given * number value. 
This feature are mainly used to solve plural format issue into case * A message has different plural forms in some languages. * @param string $category message category. Please use only word letters. Note, category ' Yii ' are * reserved for the YII framework core code use.
@link Cphpmessagesource} for * More interpretation about category. * @param string $message The original message * @param array $params parameters to is applied to the message using <cod
E>strtr</code>.
* Starting from version 1.0.2, the parameter can is a number without key.
* And in this case, the method would call {@link Cchoiceformat::format} to choose * A appropriate message translation. * Starting from version 1.1.6 with 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 t
He rest messages. * @param string $language the target language.
If null (default), the {@link capplication::getlanguage application language} would 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 the array in $mesage to match the translations.

Specific use methods such as:

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

Of course, you can use the command line command message provided by YIIC to translate, the specific reference YIIC command instructions

Date/time, money, and number formats

Date/Time Processing Cdateformatter class
Specific reference (/yii_dev/yii/framework/i18n/cdateformatter.php) class file

Digital processing
specific Reference (/yii_dev/yii/framework/i18n/cnumberformatter.php) class file

More about Yii related content readers can view the site topics: "Yii framework Introduction and common skills Summary", "PHP Excellent Development Framework Summary", "Smarty Template Primer Tutorial", "PHP date and Time usage summary", "PHP object-oriented Programming Program", " Summary of PHP string usage, Introduction to PHP+MYSQL database operations, and a summary of PHP common database operations Tips

I hope this article will help you with the PHP program design based on the YII framework.

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.