ThinkPHP multi-language support and multi-template support Overview, thinkphp overview _ PHP Tutorial

Source: Internet
Author: User
ThinkPHP multi-language support and multi-template support Overview, thinkphp overview. ThinkPHP multi-language support and multi-template support overview. thinkphp overview This article describes ThinkPHP multi-language support and multi-template support in the form of examples. ThinkPHP is a very important technique in ThinkPHP. it is divided into thinkphp multi-language support and multi-template support Overview, ThinkPHP overview

This article describes ThinkPHP's multi-language support and multi-template support in the form of examples. 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.


How does thinkphp30 implement multi-language switching?

Return array (
'Lang _ SWITCH_ON '=> true,
'Default _ lang' => 'zh-cn', // DEFAULT Language
'Lang _ AUTO_DETECT '=> true, // automatic language detection
'Lang _ list' => 'en-us, zh-cn, zh-tw '// a list of allowed languages must be written.
);
?>
Download the full version of thinkphp3.0 from thinkphp official website and have an example of exmples/lang.
It's hard to say that you can understand the example.

How can I switch multiple templates of Thinkphp in multiple languages,

Generally, you can change the language pack. I think there are many differences between your English and Chinese templates.
You can easily add the following code to index. php:
If (isset ($ _ GET ['L']) {$ _ GET ['t'] = $ _ GET ['L'];} in addition, remember to add the following configuration in the configuration file:
'Default _ THEME '=> 'default', 'tmpl _ DETECT_THEME' => true, // examples of automatic template topic template switching:
Www.thinkphp1.cn/extend/234.html


This article describes ThinkPHP's multi-language support and multi-template support in the form of examples. ThinkPHP is a very important technique...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.