From 84f093ab42dc04f0cba1acbc5fe9c65dcf665979 Mon Sep 17 00:00:00 2001 From: xuxueli <931591021@qq.com> Date: Fri, 19 Jan 2018 17:49:42 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=BD=E9=99=85=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/xxl/job/admin/core/util/I18nUtil.java | 41 ++++++++++++++++--- .../main/resources/i18n/message.properties | 1 + .../WEB-INF/template/common/common.macro.ftl | 29 ++++++------- .../src/main/webapp/WEB-INF/template/help.ftl | 14 ++----- .../main/webapp/WEB-INF/template/index.ftl | 21 ++++------ .../template/jobcode/jobcode.index.ftl | 2 +- .../template/jobgroup/jobgroup.index.ftl | 4 +- .../template/jobinfo/jobinfo.index.ftl | 5 +-- .../WEB-INF/template/joblog/joblog.detail.ftl | 6 +-- .../WEB-INF/template/joblog/joblog.index.ftl | 4 +- .../main/webapp/WEB-INF/template/login.ftl | 25 +++-------- .../src/main/webapp/static/js/common.1.js | 23 ++++++----- .../src/main/webapp/static/js/index.js | 2 +- .../src/main/webapp/static/js/login.1.js | 25 +++++------ .../com/xxl/job/admin/util/I18nUtilTest.java | 20 +++++++++ 15 files changed, 125 insertions(+), 97 deletions(-) create mode 100644 xxl-job-admin/src/test/java/com/xxl/job/admin/util/I18nUtilTest.java diff --git a/xxl-job-admin/src/main/java/com/xxl/job/admin/core/util/I18nUtil.java b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/util/I18nUtil.java index d158b5bb..643d9ace 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/admin/core/util/I18nUtil.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/util/I18nUtil.java @@ -1,5 +1,6 @@ package com.xxl.job.admin.core.util; +import com.xxl.job.core.util.JacksonUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.core.io.ClassPathResource; @@ -8,6 +9,8 @@ import org.springframework.core.io.support.EncodedResource; import org.springframework.core.io.support.PropertiesLoaderUtils; import java.io.IOException; +import java.util.HashMap; +import java.util.Map; import java.util.Properties; /** @@ -19,14 +22,12 @@ 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_cache && prop != null) { - return prop; + if (prop != null) { + //return prop; } - try { Resource resource = new ClassPathResource(i18n_file); EncodedResource encodedResource = new EncodedResource(resource,"UTF-8"); @@ -37,8 +38,38 @@ public class I18nUtil { return prop; } + /** + * get val of i18n key + * + * @param key + * @return + */ public static String getString(String key) { return loadI18nProp().getProperty(key); } + /** + * get mult val of i18n mult key, as json + * + * @param keys + * @return + */ + public static String getMultString(String... keys) { + Map map = new HashMap<>(); + + Properties prop = loadI18nProp(); + if (keys!=null && keys.length>0) { + for (String key: keys) { + map.put(key, prop.getProperty(key)); + } + } else { + for (String key: prop.stringPropertyNames()) { + map.put(key, prop.getProperty(key)); + } + } + + String json = JacksonUtil.writeValueAsString(map); + return json; + } + } diff --git a/xxl-job-admin/src/main/resources/i18n/message.properties b/xxl-job-admin/src/main/resources/i18n/message.properties index c15cedef..7400e7fa 100644 --- a/xxl-job-admin/src/main/resources/i18n/message.properties +++ b/xxl-job-admin/src/main/resources/i18n/message.properties @@ -1,5 +1,6 @@ admin_name=任务调度中心 admin_name_full=分布式任务调度平台XXL-JOB +admin_version=1.9.1(快照版本) ## system system_tips=系统提示 diff --git a/xxl-job-admin/src/main/webapp/WEB-INF/template/common/common.macro.ftl b/xxl-job-admin/src/main/webapp/WEB-INF/template/common/common.macro.ftl index c66f7c3c..de3c4cd2 100644 --- a/xxl-job-admin/src/main/webapp/WEB-INF/template/common/common.macro.ftl +++ b/xxl-job-admin/src/main/webapp/WEB-INF/template/common/common.macro.ftl @@ -29,6 +29,10 @@ + + <#-- i18n --> + <#global I18n = I18nUtil.getMultString()?eval /> + <#macro commonScript> @@ -55,14 +59,7 @@ @@ -71,7 +68,7 @@