Blogger Information
Blog 55
fans 0
comment 0
visits 59443
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
Thinkphp5 中英文切换示例
南鸢离梦的博客
Original
2032 people have browsed it
  1. 开启配置
  2. 'lang_switch_on' => true,
  3. 'lang_list' => ['zh-cn','en-us'],
  4. 定义语言包
  5. 框架或模块目录\lang\zh-cn.php
  6. return [
  7. 'CHINESE'=>'中文',
  8. 'ENGLISH' =>'英文',
  9. ]
  10. 框架或模块目录\lang\en-us.php
  11. return [
  12. '中文'=>'CHINESE',
  13. '英文' =>'ENGLISH',
  14. ]
  15. 控制器中方法
  16. public function changelang() {
  17. $lang=input('lang');
  18. switch ($lang) {
  19. case 'en':
  20. cookie('think_var', 'en-us');
  21. break;
  22. case 'zn':
  23. cookie('think_var', 'zh-cn');
  24. break;
  25. default:
  26. cookie('think_var','zh-cn');
  27. break;
  28. }
  29. }
  30. HTML示例
  31. <!DOCTYPE html>
  32. <html lang="en">
  33. <head>
  34. <meta charset="UTF-8">
  35. <title>Title</title>
  36. </head>
  37. <body>
  38. <div style="background: lightskyblue;width: 150px;height: 20px;">
  39. {:lang('CHINESE')}
  40. </div>
  41. <div style="background: forestgreen;width: 150px;height: 20px;">
  42. {:lang('ENGLISH')}
  43. </div>
  44. <br><br><br>
  45. <hr>
  46. <button class="n" lang="zn">中文</button>
  47. <button class="n" lang="en">英文</button>
  48. <script src="http://libs.baidu.com/jquery/1.10.2/jquery.js"></script>
  49. <script>
  50. $('.n').click(function(){
  51. var data={'lang':$(this).attr('lang')};
  52. console.log(data.lang);
  53. $.get("{:url('changelang')}",data,function(){
  54. location.reload();
  55. })
  56. })
  57. </script>
  58. </body>
  59. </html>
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post