import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.*; public class I18nUtils { private static final Map<String, Map<String, String>> i18nData = new HashMap<>(); public static Map<String, String> getI18nByLangCode(String langCode) {
langCode = langCode.toLowerCase();
String fileName = "string_" + langCode + ".properties";
return i18nData.get(fileName);
} public static Map<String, String> getI18nMap(String langCode) {
Map<String, String> m = getI18nByLangCode(langCode);
if (m == null) {
m = getI18nByLangCode("en");
}
return m;
} public static void loadI18nResouce() throws Exception { String path = I18nUtils.class.getResource("/").getPath(); File f = new File(path + "/i18n"); if (f.exists() && f.isDirectory()) { File[] files = f.listFiles(); if (files != null && files.length > 0) { for (File file : files) { String fileName = file.getName(); if (fileName.startsWith("string_") && fileName.endsWith(".properties")) { InputStream in = new FileInputStream(file); Properties properties = new Properties(); properties.load(in); Map<String, String> map = toMap(properties); i18nData.put(fileName, map); in.close();
properties.clear(); } } } } } private static Map<String, String> toMap(Properties properties) { Map<String, String> map = new HashMap<>(); Enumeration<?> names = properties.propertyNames(); while (names.hasMoreElements()) {
Object name = names.nextElement(); if (name != null) { String name1 = name.toString(); String value = properties.getProperty(name1); map.put(name1, value);
}
} return map; } }

  

I18nUtils的更多相关文章

  1. 测试驱动开发实践3————testSave之新增用户

    内容指引 1.确定新增用户的业务规则 2.根据业务规则设计测试用例 3.为测试用例赋值并驱动开发 一.确定新增用户的规则 1.注册用户允许通过"用户名+密码"."手机号+ ...

  2. SpringBoot 消息国际化配置

    一.目的 针对不同地区,设置不同的语言信息. SpringBoot国际化配置文件默认放在classpath:message.properties,如果自定义消息配置文件,需要application.p ...

随机推荐

  1. WebApi 全局使用filter

    先上代码: public static class WebApiConfig { public static void Register(HttpConfiguration config) { // ...

  2. js获取子元素的内容

    <div class="aaa1"> <div class="">123</div> <span>2222< ...

  3. css3的transform-origin配合scale,控制动画,实现各种hover效果

    1.底部画线,从左边开始,右边结束 html: <div class="silde-txt">底部划线</div> css: <style>.s ...

  4. IIS SSL证书 指定的登录会话不存在,可能已被终止 HRESULT:0x80070520

    指定的登录会话不存在,可能已被终止 HRESULT:0x80070520 IIS导入证书时,选择”允许导出此证书” 服务器证书名称,在mmc控制台中个人证书中命名

  5. http协议文件与数据上传、及上传图片io流错误

    package com.smartdoer.utils; import java.io.BufferedReader; import java.io.ByteArrayOutputStream; im ...

  6. windows mysql 的myini

    地址 :C:\ProgramData\MySQL\MySQL Server 5.7

  7. Apache Flume 学习笔记

    # 从http://flume.apache.org/download.html 下载flume ############################################# # 概述: ...

  8. GPU知识了解

    前言 今天在使用阿里云的时候,无意间看到了有GPU服务器,于是对它做了一个大概的了解. 概念 GPU是Graphics Processing Unit的缩写,翻译成中文就是图形处理器.是一种专门在个人 ...

  9. 洛谷 P1763 状态压缩dp+容斥原理

    (题目来自洛谷oj) 一天,maze决定对自己的一块n*m的土地进行修建.他希望这块土地共n*m个格子的高度分别是1,2,3,...,n*m-1,n*m.maze又希望能将这一些格子中的某一些拿来建蓄 ...

  10. JAVA高级篇(二、JVM内存模型、内存管理之第二篇)

    本文转自https://zhuanlan.zhihu.com/p/25713880. JVM的基础概念 JVM的中文名称叫Java虚拟机,它是由软件技术模拟出计算机运行的一个虚拟的计算机. JVM也充 ...