新增语言包内容和js调整

This commit is contained in:
toogee 2020-11-02 21:54:26 +08:00
parent 7495de7e09
commit 4ad5e23b97
8 changed files with 66 additions and 33 deletions

View File

@ -0,0 +1,30 @@
<?php
// +----------------------------------------------------------------------
// | 状态提示
// +----------------------------------------------------------------------
namespace app\common\controller;
use think\facade\Cookie;
class Language
{
public function select($lang)
{
switch ($lang) {
case 'cn':
Cookie::set('think_lang','zh-cn');
break;
case 'en':
Cookie::set('think_lang','en-us');
break;
case 'tw':
Cookie::set('think_lang','zh-tw');
break;
default:
break;
}
return true;
}
}

View File

@ -31,6 +31,7 @@ class Msg
'add_error' => Lang::get('add error'),
'edit_success' => Lang::get('edit success'),
'edit_error' => Lang::get('edit error'),
'illegal_request' => Lang::get('illegal request'),
];

View File

@ -11,6 +11,7 @@ use app\common\model\User;
use app\common\model\Cate;
use app\common\model\Comment;
use think\facade\Cookie;
use app\common\lib\Msg;
class Index extends BaseController
{
@ -163,23 +164,16 @@ class Index extends BaseController
}
public function select()
public function language()
{
$lang = input('language');
//dump($lang);
switch ($lang) {
case 'cn':
Cookie::set('think_lang','zh-cn');
break;
case 'en':
Cookie::set('think_lang','en-us');
break;
case 'tw':
Cookie::set('think_lang','zh-tw');
break;
default:
break;
if(request()->isPost()){
$language = new \app\common\controller\Language;
$lang = $language->select(input('language'));
if($lang){
return json(['code'=>0,'msg'=>'']);
}
}else {
return json(['code'=>Msg::get('error'),'msg'=>Msg::getMsg('illegal_request')]);
}
}

View File

@ -1,6 +1,11 @@
<?php
return [
//语言
'language' => 'language',
'chinese' => '中文简体',
'english' => 'english',
//menu
'index' => 'Index',
'home page' => 'Home page',
@ -48,9 +53,6 @@ return [
'ads area' => 'Ads area',
'enclosure' => 'enclosure',
'download files' => 'Download files',
//message
'add' => 'add',
@ -60,4 +62,5 @@ return [
'add error' => 'add error',
'edit success' => 'articel edit success',
'edit error' => 'articel edit error',
'illegal_request' => 'illegal request',
];

View File

@ -1,7 +1,12 @@
<?php
return [
//menu
//语言
'language' => 'language',
'chinese' => '中文简体',
'english' => 'english',
//menu
'index' => 'index',
'home page' => '首页',
'user center' => '用户中心',
@ -16,7 +21,7 @@ return [
'case' => '案例',
'timeline' => '框架日志',
//帖子
//帖子
'title color' => '颜色',
'add_post' => '添加帖子',
'my collection' => '我的收藏',
@ -48,12 +53,13 @@ return [
'ads area' => '广告区',
'enclosure' => '附件',
'download files' => '下载文件',
//message
'add' => '添加',
'delete' => '删除',
'add success' => '添加成功!',
'add error' => '添加失败',
'edit success' => '修改成功',
'edit error' => '修改失败',
'illegal request' => '非法请求',
];

View File

@ -851,12 +851,13 @@ layui.define(['layer', 'laytpl', 'form', 'element', 'upload', 'util'], function(
});
});
//监听语音选择提交
form.on('select(language)', function(data){
var data = data.value;
$.post(langUrl,{language:data},function(result){
location.reload();
//监听语音选择提交
$('#language').on('change',function(){
var data = $(this).val();
$.post(langUrl,{language:data},function(res){
if(res.code == 0){
location.reload();
}
});
return false;
});

View File

@ -18,6 +18,6 @@ var messageNums = "{:url('index/Message/nums')}",
websearch = "{:url('index/index/search')}",
textImgUpload = "{:url('index/article/textImgUpload')}",
searchUrl = "{:url('index/search')}";
langUrl = "{:url('index/select')}";
langUrl = "{:url('index/language')}";
</script>

View File

@ -53,13 +53,11 @@
<a href="{:url('login/reg')}">{:lang('register')}</a>
</li>
<li class="layui-nav-item">
<div class="layui-form" style="width:98px;line-height:20px;color:black;padding: 0 2px;">
<select name="language" lay-filter="language" lay-verify="">
<select name="language" lay-filter="language" lay-verify="" id="language">
<option value="cn" {if cookie('think_lang')=='zh-cn'} selected{/if} >中文简体</option>
<option value="tw" {if cookie('think_lang')=='zh-tw'} selected{/if} >中文繁体</option>
<option value="en" {if cookie('think_lang')=='en-us'} selected{/if} >Englishi</option>
<option value="en" {if cookie('think_lang')=='en-us'} selected{/if} >English</option>
</select>
</div>
</li>
<!--li class="layui-nav-item layui-hide-xs">
<a href="" onclick="layer.msg('正在通过QQ登入', {icon:16, shade: 0.1, time:0})" title="QQ登入" class="iconfont icon-qq"></a>