YiiFramework development tutorial examples of multiple languages

Source: Internet
Author: User
In general, to achieve information translation, you need to perform the following steps: call Yii: t (); in the appropriate location to protected/messages/LocaleID/CategoryName. create a php translation file in PHP format. Each file simply returns an information translation array. Note that ,... "/> SyntaxH in general, to achieve information translation, you need to perform the following steps: call Yii: t (); in the appropriate position to protected/messages/LocaleID/CategoryName. create a php translation file in PHP format. Each file simply returns an information translation array. Note that it is assumed that you use the default CPhpMessageSource to store translation information. Configure CApplication: sourceLanguage and CApplication: language. Therefore, the first step is to add the appropriate configuration for the Application: [php] Dirname (_ FILE __). DIRECTORY_SEPARATOR. '.. ', 'sourcelanguage' => 'en', 'language' => 'zh _ cn', 'name' => 'i18ndemo ',... // application components 'components' => array ('coremessages '=> array ('basepath' => 'protected/messages ',),),); Dirname (_ FILE __). DIRECTORY_SEPARATOR. '.. ', 'sourcelanguage' => 'en', 'language' => 'zh _ cn', 'name' => 'i18ndemo ',... // application components 'components' => array ('coremessages '=> array ('basepath' => 'protected/messages',),); the source language is en, the directory language is Chinese (zh_cn), and the translation information directory is protected/messages. then protected/messages is used to create the zh_cn Directory. to support other languages, you can create a directory and then create a yii in zh_cn. php, in which yii is used as the classification name during translation (you can choose your preferred name ). Check where the code needs to be translated, and then in yii. [php] return array ('application name' => 'application name ', 'Greetings from Santa '=> 'Greetings from Santa Claus', 'firstname' => 'name', 'lastname' => 'surname ', 'Choose your Christmas Gift '=> 'Select your favorite Christmas Gift', 'iPad '=> 'iPad', 'remote control helicopter '=> 'Remote control helicopter ', '60 inch 3D led TV '=> '60 inch 3D led TV', 'Holy le Le' => 'bibb ', 'Choose your Christmas dinner' => 'choose your Christmas dinner ', 'egg' => 'eg', 'ham' => 'hams ', 'chicken' => 'Chicken ', 'pork' => 'pork', 'beer' => 'Beer ', 'Coke' => 'Cola ', 'wine' => 'liquor ', 'submit' => 'submit', 'Merry Christmas '=> 'Merry Christmas', 'On Christmas Day, you will be given '=> 'You will get on Christmas Day',' And you will have '=>' You can have ', 'for Christmas dinner' => 'for Christmas dinner', 'Start Again '=>' reselect '); 1. replace the original English string with yii :: t ('yii', xxx); for example, DataModel. php 1 public function getGifts () {return array ('1' => Yii: t ('yii', 'iPad'), '2' => yii :: t ('yii', 'remote control helicopter '), '3' => yii: t ('yii', '60 inch 3D led TV '), '4' => Yii: t ('yii', 'Holy le Le'),);} public function getMeals () {return array ('1' => yii :: t ('yii', 'egg'), '2' => yii: t ('yii', 'ham'), '3' => Yii :: t ('yii', 'chicken'), '4' => yii: t ('yii', 'pork'), '5' => Yii :: t ('yii', 'beer'), '6' => yii: t ('yii', 'Coke'), '7' => Yii :: t ('yii', 'wine'),);} return array ('application name' => 'application name ', 'Greetings from Santa '=> 'Greetings from Santa Claus', 'firstname' => 'name', 'lastname' => 'surname ', 'Choose your Christmas Gift '=> 'Select your favorite Christmas Gift', 'iPad '=> 'iPad', 'remote control helicopter '=> 'Remote control helicopter ', '60 inch 3D led TV '=> '60 inch 3D led TV', 'Holy le Le' => 'bibb ', 'Choose your Christmas dinner' => 'choose your Christmas dinner ', 'egg' => 'eg', 'ham' => 'hams ', 'chicken' => 'Chicken ', 'pork' => 'pork', 'beer' => 'Beer ', 'Coke' => 'Cola ', 'wine' => 'liquor ', 'submit' => 'submit', 'Merry Christmas '=> 'Merry Christmas', 'On Christmas Day, you will be given '=> 'You will get on Christmas Day',' And you will have '=>' You can have ', 'for Christmas dinner' => 'for Christmas dinner', 'Start Again '=>' reselect '); 1. replace the original English string with yii :: t ('yii', xxx); for example, DataModel. php1public function getGifts () {return array ('1' => Yii: t ('yii', 'iPad'), '2' => yii :: t ('yii', 'remote control helicopter '), '3' => yii: t ('yii', '60 inch 3D led TV '), '4' => Yii: t ('yii', 'Holy le Le'),);} public function getMeals () {return array ('1' => yii :: t ('yii', 'egg'), '2' => yii: t ('yii', 'ham'), '3' => Yii :: t ('yii', 'chicken'), '4' => yii: t ('yii', 'pork'), '5' => Yii :: t ('yii', 'beer'), '6' => yii: t ('yii', 'Coke'), '7' => Yii :: t ('yii', 'wine '),);}

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.