当前位置:网站首页>ThinkPHP5多语言切换项目实战
ThinkPHP5多语言切换项目实战
2022-06-24 08:08:00 【BigChen_up】
ThinkPHP5多语言切换实战
1.在配置文件中开启多语言配置
2.然后添加多语言目录
这里创建你需要的语言包
在语言包里定义需要翻译的文本,中英文数组的键名写成一致

然后在html文件里输入 {:lang(‘键名’)} 对应的键名。就是下图的写法。
上边都做完以后就可以开始撸代码了:
首先在前端写一个切换语言的AJAX请求PHP文件
<div class="language" hidden>
<p class="toggle" lang='zh' >{
:lang('简体中文')}</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();
})
})
然后在控制器中接受到传递过来请求的参数:
// 多语言切换
public function lang() {
switch ($_GET['lang']) {
// 根据传递过来的参数来判断
case 'en': // 英文
cookie('think_var','en-us'); // 通过cookie来设置语言
break;
case 'zh': // 简体中文
cookie('think_var','zh-cn');
break;
default:
break;
}
}
点击切换就可以实现中英文切换啦
效果如下图:

边栏推荐
猜你喜欢

"I can't understand Sudoku, so I choose to play Sudoku."

支持向量机(SVC,NuSVC,LinearSVC)

最新Windows下Go语言开发环境搭建+GoLand配置
![[noi Simulation Competition] send (tree DP)](/img/5b/3beb9f5fdad00b6d5dc789e88c6e98.png)
[noi Simulation Competition] send (tree DP)
![[ES6 breakthrough] promise is comparable to native custom encapsulation (10000 words)](/img/b3/b156d75c7b4f03580c449f8499cd74.png)
[ES6 breakthrough] promise is comparable to native custom encapsulation (10000 words)

jupyter入门常见的几个坑:

零基础自学SQL课程 | 相关子查询

PhpStrom代码格式化设置

The native applet uses canvas to make posters, which are scaled to the same scale. It is similar to the uniapp, but the writing method is a little different

Recommendation - Secret of curiosity: how many dancing angels can stand on the tip of a needle?
随机推荐
Squid代理服务器应用
【Redis實現秒殺業務①】秒殺流程概述|基本業務實現
The printed object is [object object]. Solution
Redis implements a globally unique ID
Essay - Reflection
P6117-[JOI 2019 Final]コイン集め【贪心】
P6698-[balticoi 2020 day2] virus [AC automata, DP, SPFA]
Installation of sophus package in slam14 lecture
Weekly recommended short video: talk about "meta universe" with a serious attitude
[redis implements seckill business ①] seckill process overview | basic business implementation
Epidemic situation, unemployment, 2022, we shouted to lie down!
Dynamic saving and recovery of FPU context under risc-v architecture
Time Series Data Augmentation for Deep Learning: A Survey 之论文阅读
198. house raiding
cookie加密 4 rpc方法确定cookie加密
Directly applicable go coding specification
Spark - the number of leftouterjoin results is inconsistent with that of the left table
[bug] @jsonformat has a problem that the date is less than one day when it is used
Threejs glow channel 01 (unrealbroompass & layers)
2022.6.13-6.19 AI行业周刊(第102期):职业发展