国际化

This commit is contained in:
xuxueli 2018-01-17 21:36:45 +08:00
parent 82d6375e63
commit d24b7a308f
18 changed files with 134 additions and 41 deletions

View File

@ -1,5 +1,7 @@
package com.xxl.job.admin.controller.interceptor;
import com.xxl.job.admin.core.util.FtlUtil;
import com.xxl.job.admin.core.util.I18nUtil;
import org.apache.commons.lang3.ArrayUtils;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
@ -19,7 +21,8 @@ public class CookieInterceptor extends HandlerInterceptorAdapter {
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
ModelAndView modelAndView) throws Exception {
// cookie
if (modelAndView!=null && ArrayUtils.isNotEmpty(request.getCookies())) {
HashMap<String, Cookie> cookieMap = new HashMap<String, Cookie>();
for (Cookie ck : request.getCookies()) {
@ -27,6 +30,11 @@ public class CookieInterceptor extends HandlerInterceptorAdapter {
}
modelAndView.addObject("cookieMap", cookieMap);
}
// static method
if (modelAndView != null) {
modelAndView.addObject("I18nUtil", FtlUtil.generateStaticModel(I18nUtil.class.getName()));
}
super.postHandle(request, response, handler, modelAndView);
}

View File

@ -0,0 +1,25 @@
package com.xxl.job.admin.core.util;
import freemarker.ext.beans.BeansWrapper;
import freemarker.template.TemplateHashModel;
/**
* ftl util
*
* @author xuxueli 2018-01-17 20:37:48
*/
public class FtlUtil {
public static TemplateHashModel generateStaticModel(String packageName) {
try {
BeansWrapper wrapper = BeansWrapper.getDefaultInstance();
TemplateHashModel staticModels = wrapper.getStaticModels();
TemplateHashModel fileStatics = (TemplateHashModel) staticModels.get(packageName);
return fileStatics;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}

View File

@ -10,14 +10,20 @@ import org.springframework.core.io.support.PropertiesLoaderUtils;
import java.io.IOException;
import java.util.Properties;
/**
* i18n util
*
* @author xuxueli 2018-01-17 20:39:06
*/
public class I18nUtil {
private static Logger logger = LoggerFactory.getLogger(I18nUtil.class);
private static final String i18n_file = "i18n/message.properties";
private static Properties prop = null;
private static boolean prop_cache = false;
public static Properties loadI18nProp(){
if (prop == null) {
if (prop_cache && prop == null) {
try {
Resource resource = new ClassPathResource(i18n_file);
EncodedResource encodedResource = new EncodedResource(resource,"UTF-8");

View File

@ -1 +1,21 @@
admin_name=任务调度中心
admin_name=任务调度中心
login_btn=登录
login_remember_me=记住密码
login_username_placeholder=请输入登录账号
login_password_placeholder=请输入登录密码
login_username_empty=请输入登录账号
login_username_lt_5=登录账号不应低于5位
login_password_empty=请输入登录密码
login_password_lt_5=登录密码不应低于5位
login_success=登录成功
login_fail=登录失败
logout_btn=注销
logout_confirm=确认注销登录?
logout_success=注销成功
logout_fail=注销失败
system_tips=系统提示
system_ok=确定2
system_close=关闭2

View File

@ -0,0 +1,6 @@
admin_name=Job Scheduling Center
login_btn=Login
login_remember_me=Remember Me
login_username_placeholder=Please input username
login_password_placeholder=Please input password

View File

@ -0,0 +1,6 @@
admin_name=任务调度中心
login_btn=登录
login_remember_me=记住密码
login_username_placeholder=请输入登录账号
login_password_placeholder=请输入登录密码

View File

@ -53,7 +53,17 @@
<#-- common -->
<script src="${request.contextPath}/static/js/common.1.js"></script>
<script>var base_url = '${request.contextPath}';</script>
<script>
var base_url = '${request.contextPath}';
var system_tips = '${I18nUtil.getString("system_tips")}';
var system_ok = '${I18nUtil.getString("system_ok")}';
var system_close = '${I18nUtil.getString("system_close")}';
var logout_confirm = '${I18nUtil.getString("logout_confirm")}';
var logout_success = '${I18nUtil.getString("logout_success")}';
var logout_fail = '${I18nUtil.getString("logout_fail")}';
</script>
</#macro>
@ -61,7 +71,7 @@
<header class="main-header">
<a href="${request.contextPath}/" class="logo">
<span class="logo-mini"><b>XXL</b></span>
<span class="logo-lg"><b>任务调度中心</b></span>
<span class="logo-lg"><b>${I18nUtil.getString("admin_name")}</b></span>
</a>
<nav class="navbar navbar-static-top" role="navigation">
<a href="#" class="sidebar-toggle" data-toggle="offcanvas" role="button"><span class="sr-only">切换导航</span></a>
@ -69,7 +79,7 @@
<ul class="nav navbar-nav">
<li class="dropdown user user-menu">
<a href=";" id="logoutBtn" class="dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
<span class="hidden-xs">注销</span>
<span class="hidden-xs">${I18nUtil.getString("logout_btn")}</span>
</a>
</li>
</ul>
@ -175,7 +185,7 @@
<#macro commonFooter >
<footer class="main-footer">
Powered by <b>XXL-JOB</b> 1.9.1快照版本
Powered by <b>XXL-JOB</b> 1.9.1SNAPSHOT
<div class="pull-right hidden-xs">
<strong>Copyright &copy; 2015-${.now?string('yyyy')} &nbsp;
<a href="http://www.xuxueli.com/" target="_blank" >xuxueli</a>

View File

@ -1,7 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<title>任务调度中心</title>
<title>${I18nUtil.getString("admin_name")}</title>
<#import "/common/common.macro.ftl" as netCommon>
<@netCommon.commonStyle />
</head>
@ -16,7 +16,7 @@
<div class="content-wrapper">
<!-- Content Header (Page header) -->
<section class="content-header">
<h1>使用教程<small>任务调度中心</small></h1>
<h1>使用教程</h1>
<!--
<ol class="breadcrumb">
<li><a><i class="fa fa-dashboard"></i>调度中心</a></li>

View File

@ -1,7 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<title>任务调度中心</title>
<title>${I18nUtil.getString("admin_name")}</title>
<#import "/common/common.macro.ftl" as netCommon>
<@netCommon.commonStyle />
<!-- daterangepicker -->
@ -18,8 +18,9 @@
<div class="content-wrapper">
<!-- Content Header (Page header) -->
<section class="content-header">
<h1>运行报表<small>任务调度中心</small></h1>
<h1>运行报表</h1>
<!--
<h1>运行报表<small>任务调度中心</small></h1>
<ol class="breadcrumb">
<li><a><i class="fa fa-dashboard"></i>调度中心</a></li>
<li class="active">使用教程</li>

View File

@ -1,7 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<title>任务调度中心</title>
<title>${I18nUtil.getString("admin_name")}</title>
<#import "/common/common.macro.ftl" as netCommon>
<@netCommon.commonStyle />
<link rel="stylesheet" href="${request.contextPath}/static/plugins/codemirror/lib/codemirror.css">

View File

@ -1,7 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<title>任务调度中心</title>
<title>${I18nUtil.getString("admin_name")}</title>
<#import "/common/common.macro.ftl" as netCommon>
<@netCommon.commonStyle />
<!-- DataTables -->
@ -18,7 +18,7 @@
<div class="content-wrapper">
<!-- Content Header (Page header) -->
<section class="content-header">
<h1>执行器管理<small>任务调度中心</small></h1>
<h1>执行器管理</h1>
</section>
<!-- Main content -->

View File

@ -1,7 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<title>任务调度中心</title>
<title>${I18nUtil.getString("admin_name")}</title>
<#import "/common/common.macro.ftl" as netCommon>
<@netCommon.commonStyle />
<!-- DataTables -->
@ -19,7 +19,7 @@
<div class="content-wrapper">
<!-- Content Header (Page header) -->
<section class="content-header">
<h1>任务管理<small>任务调度中心</small></h1>
<h1>任务管理</h1>
<!--
<ol class="breadcrumb">
<li><a><i class="fa fa-dashboard"></i>调度管理</a></li>

View File

@ -1,7 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<title>任务调度中心</title>
<title>${I18nUtil.getString("admin_name")}</title>
<#import "/common/common.macro.ftl" as netCommon>
<@netCommon.commonStyle />
</head>

View File

@ -1,7 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<title>任务调度中心</title>
<title>${I18nUtil.getString("admin_name")}</title>
<#import "/common/common.macro.ftl" as netCommon>
<@netCommon.commonStyle />
<!-- DataTables -->
@ -20,7 +20,7 @@
<div class="content-wrapper">
<!-- Content Header (Page header) -->
<section class="content-header">
<h1>调度日志<small>任务调度中心</small></h1>
<h1>调度日志</h1>
<!--
<ol class="breadcrumb">
<li><a><i class="fa fa-dashboard"></i>调度日志</a></li>

View File

@ -1,7 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<title>调度中心</title>
<title>${I18nUtil.getString("admin_name")}</title>
<#import "/common/common.macro.ftl" as netCommon>
<@netCommon.commonStyle />
<link rel="stylesheet" href="${request.contextPath}/static/adminlte/plugins/iCheck/square/blue.css">
@ -13,31 +13,43 @@
</div>
<form id="loginForm" method="post" >
<div class="login-box-body">
<p class="login-box-msg">任务调度中心</p>
<p class="login-box-msg">${I18nUtil.getString("admin_name")}</p>
<div class="form-group has-feedback">
<input type="text" name="userName" class="form-control" placeholder="请输入登录账号" value="admin" >
<input type="text" name="userName" class="form-control" placeholder="${I18nUtil.getString("login_username_placeholder")}" value="admin" maxlength="18" >
<span class="glyphicon glyphicon-envelope form-control-feedback"></span>
</div>
<div class="form-group has-feedback">
<input type="password" name="password" class="form-control" placeholder="请输入登录密码" value="123456" >
<input type="password" name="password" class="form-control" placeholder="${I18nUtil.getString("login_password_placeholder")}" value="123456" maxlength="18" >
<span class="glyphicon glyphicon-lock form-control-feedback"></span>
</div>
<div class="row">
<div class="col-xs-8">
<div class="checkbox icheck">
<label>
<input type="checkbox" name="ifRemember" > Remember Me
<input type="checkbox" name="ifRemember" > ${I18nUtil.getString("login_remember_me")}
</label>
</div>
</div><!-- /.col -->
<div class="col-xs-4">
<button type="submit" class="btn btn-primary btn-block btn-flat">登录</button>
<button type="submit" class="btn btn-primary btn-block btn-flat">${I18nUtil.getString("login_btn")}</button>
</div>
</div>
</div>
</form>
</div>
<@netCommon.commonScript />
<script>
var login_username_empty = '${I18nUtil.getString("login_username_empty")}';
var login_username_lt_5 = '${I18nUtil.getString("login_username_lt_5")}';
var login_password_empty = '${I18nUtil.getString("login_password_empty")}';
var login_password_lt_5 = '${I18nUtil.getString("login_password_lt_5")}';
var login_success = '${I18nUtil.getString("login_success")}';
var login_fail = '${I18nUtil.getString("login_fail")}';
var system_tips = '${I18nUtil.getString("system_tips")}';
var system_ok = '${I18nUtil.getString("system_ok")}';
</script>
<script src="${request.contextPath}/static/plugins/jquery/jquery.validate.min.js"></script>
<script src="${request.contextPath}/static/adminlte/plugins/iCheck/icheck.min.js"></script>
<script src="${request.contextPath}/static/js/login.1.js"></script>

View File

@ -2,12 +2,12 @@ $(function(){
// logout
$("#logoutBtn").click(function(){
layer.confirm('确认注销登录?', {icon: 3, title:'系统提示'}, function(index){
layer.confirm(logout_confirm, {icon: 3, title:system_tips}, function(index){
layer.close(index);
$.post(base_url + "/logout", function(data, status) {
if (data.code == "200") {
layer.msg('注销成功');
layer.msg(logout_success);
setTimeout(function(){
window.location.href = base_url + "/";
}, 500);
@ -21,8 +21,9 @@ $(function(){
});*/
} else {
layer.open({
title: '系统提示',
content: (data.msg || "操作失败"),
title: system_tips,
btn: [system_ok, system_close],
content: (data.msg || logout_fail),
icon: '2'
});
}

View File

@ -1,8 +1,6 @@
/**
* Created by xuxueli on 17/4/24.
*/
$(function () {
// 过滤时间

View File

@ -25,14 +25,13 @@ $(function(){
},
messages : {
userName : {
required :"请输入登录账号." ,
minlength:"登录账号不应低于5位",
maxlength:"登录账号不应超过18位"
},
required : login_username_empty,
minlength : login_username_lt_5
},
password : {
required :"请输入登录密码." ,
minlength:"登录密码不应低于5位",
maxlength:"登录密码不应超过18位"
required : login_password_empty ,
minlength : login_password_lt_5
/*,maxlength:"登录密码不应超过18位"*/
}
},
highlight : function(element) {
@ -48,7 +47,7 @@ $(function(){
submitHandler : function(form) {
$.post(base_url + "/login", $("#loginForm").serialize(), function(data, status) {
if (data.code == "200") {
layer.msg('登录成功');
layer.msg(login_success);
setTimeout(function(){
window.location.href = base_url;
}, 500);
@ -62,8 +61,9 @@ $(function(){
});*/
} else {
layer.open({
title: '系统提示',
content: (data.msg || "登录失败"),
title: system_tips,
btn: [system_ok],
content: (data.msg || login_fail),
icon: '2'
});
}