This article mainly introduces ThinkPHP multi-language support and multi-template support, which is a very important technique of ThinkPHP, for more information about ThinkPHP multi-language support and multi-template support, see the following example. ThinkPHP is a very important technique. I will share it with you for your reference. The details are as follows:
I. ThinkPHP multi-language support:
Add the following to the config. php configuration file:
// Set 'Lang _ SWITCH_ON '=> true, 'default _ lang' => 'zh-cn', 'Lang _ AUTO_DETECT' => true, 'Lang _ list' => 'en-us, zh-cn, zh-tw ',
Create three folders under the Home/Lang/folder, which are zh-cn, en-us, and zh-tw, which respectively represent simplified Chinese, English, and traditional Chinese.
You can create a file corresponding to the template or a public file common. php in the folder.
En-cn/common. php page:
<? Phpreturn array ('Welcome '=> 'hello', 'lan' => 'simplified Chinese',);?>
The en-us/common. php page is as follows:
<?phpreturn array( 'welcome'=>'how are you fine?', 'lan'=>'english', );?>
The zh-tw/common. php page is as follows:
<? Phpreturn array ('Welcome '=> 'hello', 'lan' => 'Welcome Chinese',);?>
The template index. php code is as follows:
Welcome: {$ Think. lang. welcome} language: {$ Think. lang. lan} simplified Chinese english traditional Chinese
Or you can directly define L ('demo', 'test') in the Action method. in this way, you can directly apply it in the template: {$ Think. lang. demo}
In the model, for example, array ('uname', 'require ', 'username mandatory'); can be used as follows: array ('uname', 'require ', '% name ');
II. support for multiple ThinkPHP templates:
Add the following to the config. php configuration file:
// Multiple templates support 'tmpl _ SWITCH_ON '=> true, 'tmpl _ DETECT_THEME' => true,
Create other skin folders under/Home/Tpl/, such as the red folder. the files in the folder are the same as those in the default file.
Add the following in the template file:
Red default
I believe the examples described in this article are helpful for ThinkPHP learning and development.