Dorado國際化

package com.bstek.dorado.sample.basic;

import java.util.Locale;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;

import com.bstek.dorado.web.DoradoContext;

/**
 * 
 * @類名稱 LocaleResolver.java
 * @類描述 <pre></pre>
 * @作者  xingsfdz [email protected]
 * @創建時間 2019-6-2 上午12:23:11
 * @版本 1.00
 *
 * @修改記錄
 * <pre>
 *     版本                       修改人 		修改日期 		 修改內容描述
 *     ----------------------------------------------
 *     1.00 	xingsfdz 	2019-6-2             
 *     ----------------------------------------------
 * </pre>
 */
public class LocaleResolver implements
		com.bstek.dorado.core.resource.LocaleResolver {
	private final static String CURRENT_LOCALE_KEY = "com.bstek.dorado.sample.CurrentLocale";

	public Locale resolveLocale() throws Exception {
		Locale locale = null;
		HttpServletRequest request = DoradoContext.getAttachedRequest();
		boolean isView = request.getRequestURI().endsWith(".d");
//		locale = new Locale("zh", "CN");
//		locale = new Locale("en", "US");// zh_CN
		if (isView) {
			String localeParam = request.getParameter("locale");
			if (StringUtils.isNotEmpty(localeParam)) {
				locale = new Locale(StringUtils.substringBefore(localeParam,
						"_"), StringUtils.substringAfter(localeParam, "_"));
			}
			request.getSession().setAttribute(CURRENT_LOCALE_KEY, locale);
		} else {
			locale = (Locale) request.getSession().getAttribute(
					CURRENT_LOCALE_KEY);
		}

		if (locale == null) {
			locale = request.getLocale();
		}
		System.out.println("===================================" + locale);
		return locale;
	}

}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章