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. vue2.0 实现富文本编辑器功能

    前端富文本编译器使用总结: UEditor:百度前端的开源项目,功能强大,基于 jQuery,但已经没有再维护,而且限定了后端代码,修改起来比较费劲 bootstrap-wysiwyg:微型,易用,小 ...

  2. jquery+jquery.rotate实现图片旋转效果

    首先要下载jquery.min.js 和jquery.rotate.js文件 1.下载地址: https://www.jb51.net/jiaoben/554113.html 2.导入文件 <s ...

  3. js实现滚动条来动态加载数据

    主要angular2+es6 data:Array<any> //展示的数据 allData:Array<any> //全部的数据 size:number = 10 //每次动 ...

  4. Vue(九) 自定义指令

    前面介绍了许多 Vue 内置的指令,比如 v-if.v-show等,这些丰富的指令能满足我们绝大部分的业务需求,不过在需要一些特殊功能时,我们仍然希望对 DOM 进行底层的操作,这时就要用到自定义指令 ...

  5. 在python程序中的进程操作

    multiprocess模块 multiprocess不是一个模块而是python中一个操作.管理进程的包. 之所以叫multi是取自multiple的多功能的意思,在这个包中几乎包含了和进程有关的所 ...

  6. keepalived高可用集群。

    keepalived故障切换转移原理1vrrp协议:(vritual router redundancy protocol)虚拟路由冗余协议,2故障转移.keepalived三大功能1实现物理高可用, ...

  7. spoj gcdex

    题解: 首先我们设gcd(i,j)=k 所以我们就要求对于所有k的方案总数 可以线性帅选欧拉函数 然后算法一:枚举k,O(NT) 算法二:考虑到我们只要n/k的整数部分 容易证明是sqrt(n)级别的 ...

  8. Android开发 ---实现ListView的A-Z字母排序和过滤搜索功能

    效果图: 1.activity.xml 描述: 线性布局中一个层叠布局 <?xml version="1.0" encoding="utf-8"?> ...

  9. 18-09-21 numpy 的基础学习01

    # 1关于numpy 的学习import numpy as np # 一 如何创建数组****# 1 有规律的一维数据的创建======# 1 range() 和arange() 区别 貌似没有区别l ...

  10. go example

    一个简单的博客系统 https://github.com/pingguoxueyuan/gostudy/tree/master/blogger