Home  >  Article  >  Backend Development  >  Overview of ThinkPHP multi-language support and multi-template support, thinkphp overview_PHP tutorial

Overview of ThinkPHP multi-language support and multi-template support, thinkphp overview_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:20:112762browse

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

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

1. ThinkPHP multi-language support:

Add in the config.php configuration file:

//多语言支持设置
'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, namely zh-cn, en-us and zh-tw respectively representing Simplified Chinese, English and Traditional Chinese

Files corresponding to the template can be created in the

folder, or the public file common.php

zh-cn/common.php page is as follows:

<&#63;php
return array(
 'welcome'=>'你好',
 'lan'=>'简体中文', 
);
&#63;>

en-us/common.php page is as follows:

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

zh-tw/common.php page is as follows:

<&#63;php
return array(
 'welcome'=>'你好',
 'lan'=>'簡體中文', 
);
&#63;>

The template index.php code is as follows:

欢迎:{$Think.lang.welcome} 语言:{$Think.lang.lan}
<a href="&#63;l=zh-cn" rel="external nofollow" >简体中文</a>
<a href="&#63;l=en-us" rel="external nofollow" >english</a>
<a href="&#63;l=zh-tw" rel="external nofollow" >繁體中文</a>

Or define it directly in the Action method: L('demo','test'); In this way, you can apply it directly in the template: {$Think.lang.demo}
For example, in the model: array('uname','require','user name required'); can be used like this: array('uname','require','%name');

2. ThinkPHP multiple template support:

Add in the config.php configuration file:

//多模板支持
 'TMPL_SWITCH_ON'=>true,
 'TMPL_DETECT_THEME'=>true,

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

Add in the template file:

<a href="&#63;t=red" rel="external nofollow" >红</a>
<a href="&#63;t=default" rel="external nofollow" >默认</a>

I believe that the examples described in this article will be helpful to everyone’s ThinkPHP learning and development.

How to achieve multi-language switching in thinkphp30

107057517caf5e6d3dbf4bf6b1175abb true,
'DEFAULT_LANG' => 'zh-cn', // Default language
'LANG_AUTO_DETECT' = > true, // Automatically detect language
'LANG_LIST'=>'en-us,zh-cn,zh-tw'//Must write the allowed language list
);
? >
Download the full version of thinkphp3.0 from the official thinkphp website. There are examples/lang and you might as well take a look
It’s hard to say, just look at the examples and you’ll understand

Thinkphp multi-language multi-template how to switch,

In general, just change the language pack. I think your English and Chinese templates are quite different.
A relatively simple way is to add the following code to index.php:
if (isset($_GET ['l'])) { $_GET['t'] = $_GET['l'];} Also remember to add the following configuration to the configuration file
'DEFAULT_THEME' => 'default','TMPL_DETECT_THEME ' => true, // Automatic detection template theme template switching example:
www.thinkphp.cn/extend/234.html

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/868244.htmlTechArticleOverview of ThinkPHP multi-language support and multi-template support, thinkphp overview This article briefly describes ThinkPHP's multi-language support in the form of examples With multiple template support. It is a very important skill in ThinkPHP, divided into...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn