Step one: Config to open multi-language support in the configuration file of your project
' lang_switch_on ' =>true,//whether to open multi-lingual support
' Var_language ' = ' hl ',//language variable
' Lang_auto_detect ' =>true,//turn on automatic language detection
' Lang_list ' = ' zh-cn,zh-hk,en-us ',//list of supported languages
The above configuration reference CheckLangBehavior.class.php file
Second step: Turn on Checklang behavior, create a new tags.php file in the project configuration file conf directory, make the following configuration in this file
Return ' tags ' =>array (
' App_begin ' = Array (
' Behavior\readhtmlcachebehavior ',//Read static cache
' Behavior\checklangbehavior ',
),
)
The above configuration reference thinkphp/mode/common.php file
Step three: Create a language Pack file that corresponds to the language list
Create a new zh-cn.php,zh-hk.php,en-us.php file in the project/common/lang directory, and set the language variable information in these three files.
Return Array (
' username ' = ' username ',
' Password ' = ' password ',
)
Return Array (
' Username ' = ' user name ',
' Password ' = ' password ',
)
In the controller, the shortcut function L () can be used to obtain all language variable information, assigned to the template through assign, $this->assign (' Lang ', L ()) in the template to get the language variable {$lang. USERNAME}, the language variable name in the template must be capitalized.
By getting the value of a language variable, you can automatically switch languages, such as by accessing WWW.BAIDU.COM/HL/ZH-CN in a browser, and automatically loading the simplified language pack
There are 4 types of language packs, namely the entire Framework language pack, the project Common language Pack, the module language pack, the Controller language pack, the difference is the scope is different
Multi-language switching using