thinkphp Multi-language support how to configure and deploy

Source: Internet
Author: User

The framework's underlying language pack is located at:ThinkPHP/Lang/zh-cn.php 可以参考如何编写语言文件

First step: Configure the relevant options for multilingual support in the configuration file under project directory take my path for example is application\common\conf\config.php

The configuration is as follows: ' lang_switch_on ' = + true,//turn on the Language pack feature
' Lang_auto_detect ' = true,//auto-detect language
' Default_lang ' = ' zh-cn ',//default language
' Lang_list ' = ' en-us,zh-cn,zh-tw ',//must write a list of allowed languages
' Var_language ' = ' l ',//default language toggle Variable

Second step: To enable multi-lingual features, you need to configure the turn on multilingual behavior, in the application (application) configuration directory (conf) (that is, under the Application\common\conf\ folder), manually create a behavior definition file tags.php

The contents are as follows: <?php
Return Array (
Add the following line definition
' App_begin ' = = Array (' Behavior\checklangbehavior '),
);

The third step: Specific language Pack file naming and location as follows

Take my project as an example apply a language pack in application\common\ create a folder lang\ create a language file. php

For example, the Chinese language pack is:Application/Common/Lang/zh-cn.php 应用公共语言包

Fourth step: Get the corresponding language value from the language file

The controller can be directly removed with L (' key '), for example:

The contents of the language pack file are as follows: <?php
Return Array (
' Lan_define ' = ' welcome ',
);

The controller gets the following:

$value =l (' lan_define ');
$this->assign (' value ', $value);
$this->display ();

In the template: {$value}

You can also get it directly from the template: {$Think. Lang.lan_define}

thinkphp Multi-language support how to configure and deploy

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.