A System Information
Thinkphp built-in multi-lingual support, if it involves international support, then you can define the relevant language pack documentation
Thing Any output in the form of a string can define language constants.
To enable multilingual features, you need to configure the turn on multi-language behavior in the app configuration directory:
1 // common/conf Building tags.php under Application module Weibo 2 return Array (3array(' Behavior\checklangbehavior '),4 );
PS: This behavior is mainly to detect multi-lingual functions.
To configure the language in weibo/common/conf/config.php :
1 // 2 ' lang_switch_on ' = = true , 3 // 4 ' lang_auto_detect ' = true , 6 ' lang_list ' = > ' zh-cn,en-us ', 7 8 ' var_language ' = ' lang ',
At this point we begin to detect, first in weibo/home/controller/usercontroller.. PHP is not test :
1 <? php 3 use Think\controller; 6 Usercontroller extends Controller { 7 public function index () { 8 9 " 10 }
Then we enter in the address bar of the browser: http://localhost/demo39/user/test?lang=en-us , which appears as:
At this time we change the address bar is: http://localhost/demo39/user/test , then appear in the above the English display information,
At this point, because the error message is stored in the cookie, we change the address bar to: http://LOCALHOST/DEMO39/USER/TEST?LANG=ZH-CN
Then the display is Chinese:
The thinkphp system provides three default language packs, namely Simplified Chinese, English, and traditional Chinese. And these three kinds of
The language pack is guaranteed to exist: Think\lang.
We want to display the system tip information, which can be passed through the L () method to multiple language variables.
In Weibo/home/controller/usercontroller. write code in class. PHP :
1 // set the key-value pair for a language definition 2 L (' name ', ' Lee '); 3 Echo L (' name ');
This can be output: Lee ;
1 Public function index () { 2 echo L (' _module_not_exist_ '); 3 }
this is in Weibo/home/controller/usercontroller. new function in class. PHP:
1 Public function Lang () {2 Setcookie (' Think_language ', ' ZH-CN '); 3 }
Then in the browser address bar, enter http://Localhost/demo39/user/lang to the Lang function, and then at http:// In localhost/demo39/user/
Compile the index function once, will output: Unable to load the module , then change setcookie(' think_language ', ' en-us ');
Then compile the Lang function and then compile the index function, then the output: Module can ' t be loaded
If you configure many languages, a think_language cookie is automatically generated, and the default value is ZH-CN.
When we are developing the website, we will display the error message of the Chinese prompt when we encounter an error.
If you want to display other language packs, you can switch by URL:
Http://localhost/demo39/User/?lang=en-us
Two Application information
In addition to the language packs for system development information, we use more of the language definition switches in the project application. For example, a
The form supports both bilingual structures in English and Chinese.
In addition to the above configuration, the implementation of the application information in English switching needs to be configured in the application directory.
The first step: Create the Lang directory in the Home directory;
Step two: Establish zh-cn.php and en-us.php two files respectively;
Step three: Write language constants in two language packs, respectively
Code in zh-cn.php :
1 <? PHP 2 return Array (3 ' form_user ' = ' user ',4 ' form_pass ' = ' password ',5 ' form_ Email ' + ' email ',6 ' form_submit ' + ' Submit ',7 ';
Code in en-us.php :
1 <? PHP 2 return Array (3 ' form_user ' = ' user ',4 ' form_pass ' = ' pass ',5 ' form_ Email ' = ' email ',6 ' form_submit ' + ' Submit ',7 ;
Then the code in weibo/home/view/user/index.html is:
1 <form>2 <P>{$Think. Lang.form_user}:<inputtype= "text"name= "User" /></P>3 <P>{$Think. Lang.form_pass}:<inputtype= "Password"name= "Pass" /></P>4 <P>{$Think. Lang.form_email}:<inputtype= "text"name= "Email" /></P>5 <P><inputtype= "Submit"value= "{$Think. Lang.form_submit}" /></P>6 </form>
In the browser address bar type: http://localhost/demo39/user/index?lang=en-us , the display is:
Enter: HTTP://LOCALHOST/DEMO39/USER/INDEX?LANG=ZH-CN in the browser, then display as:
This function can be used to change the page display Chinese or English interface
Multi-language Settings