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. html5(一)

    HTML5 三个基本特色:结构.样式.功能. <!DOCTYPE html ><html lang="en"><head> <meta c ...

  2. Jumpserver跳板机的搭建和部署

    1.需要搭云yum仓库wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo 2. ...

  3. Linux目录结构 重要目录结构详细

    1.1 /etc/hosts ip地址与主机名(域名)的对应关系  解析主机名  ping www.baidu.com 解析成10.0.0.200 1.产品测试 2  用主机名互相访问 1.2 /et ...

  4. git 操作规范

    分支描述 长期存在 online 主分支,负责记录上线版本的迭代,该分支代码与线上代码是完全一致的. dev 开发分支,该分支记录相对稳定的版本,所有的feature分支都从该分支创建. 多套开发环境 ...

  5. Hashmap的学习整理

    这是我大致了解Hashmap的第一个博客:https://www.cnblogs.com/chengxiao/p/6059914.html 我将摘录里面的重点: 哈希表的主干就是数组 存储位置 = f ...

  6. DoTween的用法

    using UnityEngine;using System.Collections;using DG.Tweening;using UnityEngine.UI; public class Test ...

  7. [Mac]secureCRT私钥转换为mac ssh私钥

    工作环境从win迁移到mac后,win上原来用secureCRT生成的key,在mac的iterm2中不能兼容使用,导致无法再mac下登录.报错如下: key_load_public:invalid ...

  8. acrgis 解决矢量转栅格分辨率过大造成连续值变离散且出现空白

    目标:解决北京河流矢量polygon 转栅格的问题 设置栅格大小和影像一致30*30----结果发现,因为cell过大,原本连续的是矢量面变得不连续了,特别细的河流会出现间断(如下图所示): 1号 网 ...

  9. What is the RESTful API ?

    REST 是 RepresentationalStateTransfer 的缩写,一般中文译为 “表征状态转移”,Roy Thomas Fielding 在他2000年的PhD论文中发明了这个概念.首 ...

  10. HTML <form> action 属性

    当提交表单时,发送表单数据到名为 "demo_form.html" 的文件(处理输入): <form action="demo_form.html" me ...