📄 i18n.java
字号:
package com.easyjf.util;
import java.util.Properties;
import com.easyjf.web.ActionContext;
import com.easyjf.web.core.FrameworkEngine;
/**
*
* @author stef_wu
* @since 2007.3
*/
public class I18n {
private static I18n singleton = new I18n();
public static I18n getInstance() {
return singleton;
}
/**
* 初始化一个模块的国际化资源文件的名字
*
* @param moduleName
*/
public static void init(String moduleName) {
FrameworkEngine.get(moduleName, null);
}
/**
* 根据一模块的名字和语言来初始化。
*
* @param language
* @param moduleName
*/
public static void init(String language, String moduleName) {
FrameworkEngine.get(moduleName, language);
}
/**
* 先从模块名.properties里得到值
* 如果得不到,则到application_local.properties里取
* @param property
* @return
*/
public static String get(String property){
String bundle = "";
if (ActionContext.getContext().getWebInvocationParam()
.getModule().getPath().startsWith("/")) {
bundle = ActionContext.getContext().getWebInvocationParam()
.getModule().getPath().replaceAll("/", "");
}
String ret="";
try {
Properties rb = FrameworkEngine.get(bundle, null);
ret=rb.getProperty(property);
if(!StringUtils.hasText(ret)){
rb = FrameworkEngine.get("application", null);
ret=rb.getProperty(property);
}
} catch (Exception e) {
// e.printStackTrace();
}
return ret;
}
/**
* 传入一个属性值来得到一个确定的国际化表示的值。
*
* @param propertyName
* @return 多国语言指定属性的值
*/
public static String m(String propertyName) {
Properties rb = FrameworkEngine.get(null, null);
return rb.getProperty(propertyName);
}
/**
* 根据一个属性值和一个语言来得到一个确定的国际化了的值。
*
* @param propertyName
* @param language
* @return 返回指定语言的属性值
*/
public static String m(String propertyName, String language) {
Properties rb = FrameworkEngine.get(null, language);
return rb.getProperty(propertyName);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -