YII Framework Development Tutorials Multi-language Example _php tutorial

Source: Internet
Author: User
In general, to achieve information translation, you need to perform the following steps: Call Yii::t () in the appropriate location, and create a PHP translation file in protected/messages/localeid/categoryname.php format. Each file simply returns an array of information to be translated. Note that it is assumed that you use the default Cphpmessagesource to store translation information. Configure Capplication::sourcelanguage and Capplication::language. So the first step is to add the appropriate configuration for 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 directory of translation information is protected/messages. Then protected/messages create the ZH_CN directory, if you need to support other languages, you can create the appropriate directory, and then create a yii.php in Zh_cn, where Yii is the name of the classification when translating (you can choose your own favorite name). Check where the code needs to be translated, and then define the corresponding translation in the yii.php file: [PHP] return Array (' Application name ' = ' application ', ' Greetings ' from Santa ' = ') from Santa's Greetings ', ' firstName ' = ' and ' name ', ' lastName ' = ' = ', ' Choose your Christmas Gift ' + ' Choose your favorite Christmas gift ', ' ipad ' + ' ipad ', ' Remote control helicopter ' = ' RC helicopter ', ' 3D LED TV ' + ' 60 inch 3D LED Television ', ' Holy Bible ' + ' bible ', ' Choose your Christ Mas Dinner ' = ' Choose your Christmas dinner ', ' egg ' = ' eggs ', ' ham ' and ' ham ', ' Chicken ' and ' chicken ', ' pork ' and ' pork ', ' Beer ' and ' beer ', ' Coke ' + ' cola ', ' wine ' = ' liquor ', ' submit ' ' + ' submitted ', ' Merry Christmas ' and ' Merry Christmas ', ' on Christmas day,you'll be given ' =& gt; ' On Christmas Day you will receive', ' and you'll have ' = ' and you can have ', ' for Christmas dinner ' = ' as Christmas dinner ', ' Start Again ' and ' re-select '); 1 then replace the original use of the English string with yii::t (' yii ', XXX), such as datamodel.php 1 public Function getgifts () {return array (' 1 ' =>yii::t (' Yii '), ' IPad '), ' 2 ' =>yii::t (' yii ', ' Remote Control helicopter '), ' 3 ' =>yii::t (' yii ', ' 3D LED TV '), ' 4 ' =>yii::t (' Yii ', ' Holy Bible '); } 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 ' = ' and ' name ', ' LastName ' = = ' surname ', ' Choose your Christmas Gift ' + ' Choose your favorite Christmas gift ', ' ipad ' + ' ipad ', ' Remote control helicopter ' + ' RC helicopter ', ' inch 3D LED TV ' + ' 60 inch 3D LED Television ', ' Holy Bible ' + ' ' Bible ', ' Choose your Christmas dinner ' + ' Choose your Christmas dinner ', ' Egg ' = ' eggs ', ' ham ' = ' ham ', ' Chicken '= ' chicken ', ' pork ' = ' pork ', ' Beer ' and ' beer ', ' Coke ' and ' cola ', ' wine ' = ' liquor ', ' submit ' ' + ' ' submitted ', ' Merry Christmas ' = > ' Merry Christmas ', ' on Christmas day,you'll be given ' "and" on Christmas Day You'll get ', ' and you'll have ' = ' and you can have ', ' for Christmas dinner ' =& gt; ' As a Christmas dinner ', ' start Again ' = ' re-select '); 1 then replace the place where the English string was originally used for 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 '), ' Inch 3D LED TV '), ' 4 ' =>yii::t (' Yii ', ' Holy Bible '),);} 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 '),);

http://www.bkjia.com/PHPjc/477817.html www.bkjia.com true http://www.bkjia.com/PHPjc/477817.html techarticle in general, to achieve information translation, you need to perform the following steps: Call Yii::t () in the appropriate location, create a PHP translation in the protected/messages/localeid/categoryname.php format ...

  • 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.