Overview of ThinkPHP Multi language Support and Multi template Support

  • 2021-07-16 01:54:34
  • OfStack

This paper briefly describes the multi-language support and multi-template support of ThinkPHP in the form of examples. It is a very important skill in ThinkPHP, which is shared for your reference. The details are as follows:

1. ThinkPHP multilingual support:

To the config. php configuration file:


// Multilingual support settings 
'LANG_SWITCH_ON'=>true,
'DEFAULT_LANG'=>'zh-cn',
'LANG_AUTO_DETECT'=>true,
'LANG_LIST'=>'en-us,zh-cn,zh-tw',

Three folders are set up under Home/Lang/ folder, which are zh-cn, en-us and zh-tw representing simplified Chinese, English and traditional Chinese respectively

The file corresponding to the template can be created under the folder, or the common file common. php

The zh-cn/common. php page reads as follows:


<?php
return array(
 'welcome'=>' How do you do ',
 'lan'=>' Simplified Chinese ', 
);
?>

The en-us/common. php page reads as follows:


<?php
return array(
 'welcome'=>'how are you fine?',
 'lan'=>'english', 
);
?>

The zh-tw/common. php page reads as follows:


<?php
return array(
 'welcome'=>' How do you do ',
 'lan'=>' Chinese ', 
);
?>

The template index. php code is as follows:


 Welcome: {$Think.lang.welcome}  Language: {$Think.lang.lan}
<a href="?l=zh-cn" rel="external nofollow" > Simplified Chinese </a>
<a href="?l=en-us" rel="external nofollow" >english</a>
<a href="?l=zh-tw" rel="external nofollow" > Complex Chinese </a>

Or directly defined in the method of Action: L ('demo', 'Test'); In this way, it can be applied directly in the template: {$Think.lang.demo}
In the model, for example: array ('uname', 'require', 'User name required'); Can be used as follows: array ('uname', 'require', '% name');

2. ThinkPHP multi-template support:

To the config. php configuration file:


// Multiple template support 
 'TMPL_SWITCH_ON'=>true,
 'TMPL_DETECT_THEME'=>true,

/Home/Tpl/Create other skin folders, such as folder red, where the files are the same as those in default.

In the template file, add:


<a href="?t=red" rel="external nofollow" > Red </a>
<a href="?t=default" rel="external nofollow" > Default </a>

I believe the examples described in this paper are helpful for everyone to learn and develop ThinkPHP.


Related articles: