I18nUtils
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的更多相关文章
- 测试驱动开发实践3————testSave之新增用户
内容指引 1.确定新增用户的业务规则 2.根据业务规则设计测试用例 3.为测试用例赋值并驱动开发 一.确定新增用户的规则 1.注册用户允许通过"用户名+密码"."手机号+ ...
- SpringBoot 消息国际化配置
一.目的 针对不同地区,设置不同的语言信息. SpringBoot国际化配置文件默认放在classpath:message.properties,如果自定义消息配置文件,需要application.p ...
随机推荐
- RandomAccessFile多线程下载
public class DownloadServer { ; private static String fileUrl = "https://dldir1.qq.com/qqtv/mac ...
- python -- 面向对象-成员
1.成员 在类中,你能写的所有内容都是类的成员 2.变量 1.实例变量:由对象去访问的变量,一般使用是 对象 . 属性 class Person: def __in ...
- sin n次方 x 的降幂公式
A(n) = ∫ sinⁿx dx= ∫ sinⁿ⁻¹xsinx dx= - ∫ sinⁿ⁻¹x d(cosx)= - sinⁿ⁻¹xcosx + ∫ cosx • d(sinⁿ⁻¹)= - sinⁿ ...
- Mysql phpStudy升级Mysql版本,流产了怎么办?
网上有一些phpStudy升级mysql的方法,如: https://www.cnblogs.com/GreenForestQuan/p/6496431.html 很不错,我的电脑一次成功,但是同事的 ...
- CentOS 使用yum命令安装出现错误提示”could not retrieve mirrorlist http://mirrorlist.centos.org
CentOS 使用yum命令安装出现错误提示"could not retrieve mirrorlist http://mirrorlist.centos.org这个错误, 在网上找了好多, ...
- 使用Stickers拓展集成iMessage简单功能
添加一个target,选择Stickers拓展: 然后就会出现iMessage的文件夹:添加你需要的iMessage图片,这里图片遵循下面的要求: Small: 100 x 100 pt @3x sc ...
- Linux3.10.0块IO子系统流程(5)-- 为SCSI命令准备聚散列表
SCSI数据缓冲区组织成聚散列表的形式.Linux内核中表示聚散列表的基本数据结构是scatterlist,虽然名字中有list,但它只对应一个内存缓冲区,聚散列表就是多个scatterlist的组合 ...
- 论坛短信息(JSP项目)
if("list".equals(action)){ String username = request.getSession().getAttribute("login ...
- 关于iOSlaunchScreen的尺寸
备注:这里只是个人的观点,有的地方也是copy,多多指教,个人笔记,有侵犯你们版权的地方还望海涵!!! 关于launchImage 的尺寸链接 摘自:http://www.cnblogs.com/Ri ...
- js文本转语音
百度找了好多,大概分为两种,一种使用百度语音的API,另一种使用H5自带(低版本不兼容) 下面为一个模拟页面 <!DOCTYPE html><html lang="en&q ...