当前位置:网站首页>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 :

边栏推荐
- NETRCA: AN EFFECTIVE NETWORK FAULT CAUSE LOCALIZATION之论文阅读
- Nlp-d59-nlp game D28 - I think it's OK - stage summary - mentality adjustment
- 获取带参数的微信小程序二维码-以及修改二维码LOGO源码分享
- Ora-28000 error after upgrading Oracle 12C to 19C
- R ellipse random point generation and drawing
- CF566E-Restoring Map【bitset】
- 20、 Processor scheduling (RR time slice rotation, mlfq multi-level feedback queue, CFS fully fair scheduler, priority reversal; multiprocessor scheduling)
- 达梦数据库如何定位锁等待问题解决方法
- WindowManager 简单悬浮框的实现
- Algorithm - the K row with the weakest combat power in the matrix (kotlin)
猜你喜欢

如何提高网络基础设施排障效率,告别数据断档?

In depth analysis of Apache bookkeeper series: Part 3 - reading principle

从618看京东即时零售的野心

五心红娘

PhpStrom代码格式化设置

latex公式及表格识别

Why is LNX of e equal to X

Ora-28000 error after upgrading Oracle 12C to 19C
![[GDB debugging tool] | how to debug under multithreading, multiprocessing and running programs](/img/b5/38a53c88240c4308452d0208173461.png)
[GDB debugging tool] | how to debug under multithreading, multiprocessing and running programs
![[bug] @jsonformat has a problem that the date is less than one day when it is used](/img/09/516799972cd3c18795826199aabc9b.png)
[bug] @jsonformat has a problem that the date is less than one day when it is used
随机推荐
ThinkPHP 5.0 模型关联详解
Thinkphp5清除runtime下的cache缓存,temp缓存,log缓存
R 椭圆随机点产生并画图
如何解决独立站多渠道客户沟通难题?这款跨境电商插件一定要知道!
[bug] @jsonformat has a problem that the date is less than one day when it is used
Talking about the knowledge of digital transformation
Recommendation - Secret of curiosity: how many dancing angels can stand on the tip of a needle?
Oracle数据库EXPDP只导出表的方法
零基础自学SQL课程 | SQL语句语法顺序与执行顺序
php文件锁
关于thinkphp5 使用模型save()更新数据提示 method not exist:think\db\Query-&gt; 报错解决方案
Leetcode-- string
latex公式及表格识别
Turn to: CEO of Samsung Electronics: all decisions should start from recognizing yourself
Servlet fast foundation building
读CVPR 2022目标检测论文得到的亿点点启发
Time Series Data Augmentation for Deep Learning: A Survey 之论文阅读
【Eureka注册中心】
Oracle查看数据文件头SCN信息
P6698-[balticoi 2020 day2] virus [AC automata, DP, SPFA]