ThinkPHP multi-language support and multi-template support overview, thinkphp Overview

Source: Internet
Author: User

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} <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 "> traditional Chinese </a>

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:

<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 article are helpful for ThinkPHP learning and development.


How does thinkphp30 implement multi-language switching?

<? Php
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.thinkphp.cn/extend/234.html


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.