当前位置:网站首页>Thinkphp5 multi language switching project practice
Thinkphp5 multi language switching project practice
2022-06-24 09:40:00 【BigChen_ up】
ThinkPHP5 Multilingual switching practice
1. Enable multilingual configuration in the configuration file 
2. Then add a multilingual Directory
Here create the language pack you need 
Define the text to be translated in the language pack , The key names of Chinese and English arrays are written in the same way 

And then in html Enter... In the file {:lang(‘ Key name ’)} Corresponding key name . This is how the following figure is written .
Once you've done all the above, you can start rolling out the code :
First, write a switch language in the front end AJAX request PHP file
<div class="language" hidden>
<p class="toggle" lang='zh' >{
:lang(' Simplified Chinese ')}</p>
<p class="toggle" lang='en' >{
:lang('English')}</p>
</div>
$('.toggle').click(function(){
var data={
'lang':$(this).attr('lang')};
$.get("{:url('user/index/lang')}",data,function(){
location.reload();
})
})
Then the controller receives the parameters passed to the request :
// Multi language switching
public function lang() {
switch ($_GET['lang']) {
// Judge according to the passed parameters
case 'en': // english
cookie('think_var','en-us'); // adopt cookie To set the language
break;
case 'zh': // Simplified Chinese
cookie('think_var','zh-cn');
break;
default:
break;
}
}
Click switch to switch between Chinese and English
The effect is as follows :

边栏推荐
- Leetcode -- linked list
- Weekly recommended short video: talk about "meta universe" with a serious attitude
- ggplot2颜色设置总结
- Easyexcel single sheet and multi sheet writing
- 《MATLAB 神经网络43个案例分析》:第32章 小波神经网络的时间序列预测——短时交通流量预测
- threejs的点光源+环境光
- Threejs MMD model loading + contour loading + animation loading + Audio loading + camera animation loading +ammojs loading gltf model loading +gltf reflection adjustment
- Prct-1400: failed to execute getcrshome resolution
- Conseils étonnants pour promouvoir les ventes d'entreprise avec le chat en direct
- Xiaobai needs to learn MySQL - incremental statistical SQL
猜你喜欢

The ambition of JD instant retailing from 618

NETRCA: AN EFFECTIVE NETWORK FAULT CAUSE LOCALIZATION之论文阅读

Zero foundation self-study SQL course | having clause

最新Windows下Go语言开发环境搭建+GoLand配置

Easyexcel single sheet and multi sheet writing

Ora-28000 error after upgrading Oracle 12C to 19C

居家办公如何管理数据中心网络基础设施?

grpc本地测试联调工具BloomRPC

Numpy NP in numpy c_ And np r_ Explain in detail

Oracle 12c升级至19c后ORA-28000错误
随机推荐
【Eureka注册中心】
Literature Research Report
P6698-[balticoi 2020 day2] virus [AC automata, DP, SPFA]
牛客网 实现简单计算器功能
[GDB debugging tool] | how to debug under multithreading, multiprocessing and running programs
Endgame P.O.O
NETRCA: AN EFFECTIVE NETWORK FAULT CAUSE LOCALIZATION之论文阅读
php文件锁
Oracle查看数据文件头SCN信息
ThinkPHP 5.0 模型关联详解
PHP使用递归和非递归方式实现创建多级文件夹
Amazing tips for using live chat to drive business sales
零基础自学SQL课程 | 子查询
Servlet fast foundation building
Learn Tai Chi Maker - esp8226 (12) esp8266 multitasking
实战剖析:app扫码登陆实现原理(app+网页端详细逻辑)附源码
Target of cmake command_ compile_ options
ggplot2颜色设置总结
Servlet快速筑基
20、 Processor scheduling (RR time slice rotation, mlfq multi-level feedback queue, CFS fully fair scheduler, priority reversal; multiprocessor scheduling)