i18n.java.svn-base

来自「EasyJWeb是基于java技术」· SVN-BASE 代码 · 共 91 行

SVN-BASE
91
字号
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 + =
减小字号Ctrl + -
显示快捷键?