Explanation of thinkPHP multi-language switching setting methods and thinkphp setting methods
This example describes how to configure thinkPHP multi-language switching. We will share this with you for your reference. The details are as follows:
Thinkphp multi-language settings are a bit 'Tall up'. Why do you say it's a little 'Tall up? The reason why I set it for a long time is that 'the class of the initialization system must be enabled before enabling the language settings'. So, here, because of my limited experience, I think that tp multi-language settings must first initialize tp CheckLangBehavior. class. php
How to initialize CheckLangBehavior. class. php? The following is an explanation.
Under the tp framework, all modules initialize CheckLangBehavior. class. php. below:
You can understand the path. just create a new tags. php file in config. php of your public module configuration file. The content of tags. php is as follows:
<? Phpreturn array (// app_begin is actually the built-in tag of tp. It is used to trigger a behavior during tp initialization, set 'app _ begin' => array ('behavior \ CheckLangBehavior ') to trigger the multi-language function here, // enable the language function );
In the preceding checkLangBehavior. class. php file, under the built-in behavior class folder of tp, it is proved first:
Is this class exactly the same as the class above? You can go to the Library/Behavior folder of the tp framework to check whether the class exists and what the content in it is. It will not be resolved here.
After configuring the above tags. php, We must configure the tp configuration file config. php.
This config. php is in the first step above. You just need to add the following code in it:
'Lang _ SWITCH_ON '=> true, // enable the multi-language support switch 'default _ lang' => 'zh-cn ', // default language 'lang _ list' => 'zh-cn, en-us', // The LIST of languages that can be switched is separated by commas (,). 'lang _ AUTO_DETECT '=> true, // automatic language Detection
After the configuration is complete, the multi-language file configuration is completed ,:
The following is the code in the configuration en-us.php file:
<? Phpreturn array (/* core language variable */'_ WEB_NAME _' => 'travel', '_ WELLCOME _' => 'wellcome here! ',);
Code in zh-cn.php files:
<? Phpreturn array (/* core language variable */'_ WEB_NAME _' => '', '_ WELLCOME _' => 'Welcome! ',);
Below is the code for the lang method of my IndexController. class. php:
public function lang(){ $wellcome = L('_WELLCOME_'); $this->assign('wellcome', $wellcome); $this->display();}
This is the lang.html Template under the langdeskin my indexcontroller.class.php controller. Now we can test it,
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
The test results are as follows:
You can click to switch the language. If the conversion between Chinese and English is correct