更新html的多语言翻译

pull/65/head
fengshuonan 2021-01-27 23:01:39 +08:00
parent 343016494b
commit f4da698d54
3 changed files with 35 additions and 6 deletions

View File

@ -5,6 +5,7 @@ import cn.stylefeng.guns.core.beetl.tag.SysDictCheckBoxTag;
import cn.stylefeng.guns.core.beetl.tag.SysDictRadioTag; import cn.stylefeng.guns.core.beetl.tag.SysDictRadioTag;
import cn.stylefeng.guns.core.beetl.tag.SysDictSelectTag; import cn.stylefeng.guns.core.beetl.tag.SysDictSelectTag;
import cn.stylefeng.roses.kernel.auth.api.LoginUserApi; import cn.stylefeng.roses.kernel.auth.api.LoginUserApi;
import cn.stylefeng.roses.kernel.i18n.util.QuickTranslateUtil;
import cn.stylefeng.roses.kernel.system.expander.SystemConfigExpander; import cn.stylefeng.roses.kernel.system.expander.SystemConfigExpander;
import org.beetl.ext.spring.BeetlGroupUtilConfiguration; import org.beetl.ext.spring.BeetlGroupUtilConfiguration;
@ -34,6 +35,9 @@ public class CustomBeetlGroupUtilConfiguration extends BeetlGroupUtilConfigurati
// 获取基本信息的工具 // 获取基本信息的工具
groupTemplate.registerFunctionPackage("constants", SystemConfigExpander.class); groupTemplate.registerFunctionPackage("constants", SystemConfigExpander.class);
// 多语言
groupTemplate.registerFunctionPackage("translate", QuickTranslateUtil.class);
// 下拉选字典 // 下拉选字典
groupTemplate.registerTag("dict_select", SysDictSelectTag.class); groupTemplate.registerTag("dict_select", SysDictSelectTag.class);
@ -42,9 +46,6 @@ public class CustomBeetlGroupUtilConfiguration extends BeetlGroupUtilConfigurati
// 多选字典 // 多选字典
groupTemplate.registerTag("dict_checkbox", SysDictCheckBoxTag.class); groupTemplate.registerTag("dict_checkbox", SysDictCheckBoxTag.class);
// todo 多语言
// groupTemplate.registerFunctionPackage("lang", new UserTranslationContext());
} }
} }

View File

@ -54,6 +54,31 @@
var ws = layui.ws; var ws = layui.ws;
var notice = layui.notice; var notice = layui.notice;
//获取支持的语言列表
var languageRequest = new HttpRequest(Feng.ctxPath + "/i18n/getAllLanguages", 'get', function (data) {
for (var i = 0; i < data.data.length; i++) {
var code = data.data[i].code;
var description = data.data[i].name;
$("#languageDiv").append('<dd lay-unselect><a id="tran-' + code + '" href="javascript:;">' + description + '</a></dd>');
//设置监听事件,设置点击按钮切换当前系统语言
(function (code) {
$('#tran-' + code).click(function () {
var changeLanguageRequest = new HttpRequest(Feng.ctxPath + "/i18n/changeUserTranslation", 'post', function (data) {
window.location.href = Feng.ctxPath + "/";
}, function (data) {
layer.msg("切换多语言失败!" + data.message, {icon: 5, anim: 6});
});
changeLanguageRequest.set("tranLanguageCode", code);
changeLanguageRequest.start(true);
});
})(code);
}
}, function (data) {
layer.msg("获取语言列表失败!" + data.responseJSON.message, {icon: 5, anim: 6});
});
languageRequest.start();
// 默认加载主页 // 默认加载主页
index.loadHome({ index.loadHome({
menuPath: $("#firstPageAction").attr('lay-href'), menuPath: $("#firstPageAction").attr('lay-href'),
@ -106,7 +131,8 @@
timeout: false timeout: false
}); });
$('#messageDot').hide(); $('#messageDot').hide();
} catch (e) {} } catch (e) {
}
}, },
onWsClose: function (event) { onWsClose: function (event) {
//关闭连接回调 //关闭连接回调
@ -163,4 +189,4 @@
</script> </script>
</body> </body>
</html> </html>

View File

@ -55,7 +55,9 @@
</a> </a>
<dl class="layui-nav-child"> <dl class="layui-nav-child">
<dd lay-unselect><a ew-href="${ctxPath}/view/personal">个人中心</a></dd> <dd lay-unselect><a ew-href="${ctxPath}/view/personal">个人中心</a></dd>
<dd lay-unselect><a id="setPsw">修改密码</a></dd> <dd lay-unselect><a id="setPsw">${translate.get("MENU_CHANGE_PASSWORD","修改密码")}</a></dd>
<hr>
<div id="languageDiv"></div>
<hr> <hr>
<dd lay-unselect><a id="btnLogout">退出</a></dd> <dd lay-unselect><a id="btnLogout">退出</a></dd>
</dl> </dl>