我想在gwt-locale
Spring 的帮助下设置用户选择的语言环境LocaleContextHolder
。
public static final String getCurrentLocale() {
return LocaleContextHolder.getLocale().getLanguage();
}
我实际上在 Spring MVC 中有登录界面,在gwtp
. 登录之前在外部界面中选择的相同语言环境用户也必须传递给gwt
。
不幸的是,我没有看到任何 gwt 内置的语言环境设置器。
我X.gwt.xml
的默认语言环境kh
是:
<inherits name="com.google.gwt.uibinder.UiBinder" />
<inherits name="com.google.gwt.inject.Inject" />
<inherits name="com.gwtplatform.mvp.Mvp" />
<inherits name="gwtquery.plugins.droppable.Droppable"/>
<source path="client" />
<source path="shared" />
<define-configuration-property name="gin.ginjector" is-multi-valued="false"/>
<set-configuration-property name="gin.ginjector" value="com.prayagupd.client.mvp.XGInjector"/>
<set-configuration-property name="UiBinder.useSafeHtmlTemplates" value="true" />
<extend-property name="locale" values="kh" />
<extend-property name="locale" values="en" />
<set-property name="locale" value="kh"/>
<set-property-fallback name="locale" value="kh"/>
<entry-point class="com.prayagupd.client.XEntryPoint"/>
我的XEntryPoint.java
读作:
public class XEntryPoint implements EntryPoint {
private final IUserServiceAsync rpc = GWT.create(IUserService.class);
@Override
public void onModuleLoad() {
//
rpc.getLocale(new AsyncCallback<String>() {
@Override
public void onSuccess(String locale) {
GWT.log("Locale From Spring : " + locale);
GWT.log("Locale From GWT : " + LocaleInfo.getCurrentLocale().getLocaleName());
//here i want to set locale to gwt
//something like GWTLocale.setLocale(locale);
}
@Override
public void onFailure(Throwable caught) {
GWT.log(caught.getMessage());
}
});
DelayedBindRegistry.bind(ginjector);
ginjector.getPlaceManager().revealCurrentPlace();
}
}
用于 gwt 加载的 home.jsp
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" >
<%@tag import="java.util.Calendar"%>
<%@ tag body-content="scriptless"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="spr" tagdir="/WEB-INF/tags"%>
<%@ attribute name="isgwt" required="true" type="java.lang.Boolean"%>
<!-- <!DOCTYPE html> -->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="shortcut icon" type="image/png" href="/images/favicon.png" />
<script type="text/javascript" src="js/reload.captcha.js"></script>
<script type="text/javascript" src="js/date.picker.js"></script>
<link rel="stylesheet" href="/styles/innerstyle.css" type="text/css" />
<c:if test="${not isgwt}">
<link rel="stylesheet" href="/styles/mainstyler.css" type="text/css" />
<script type="text/javascript" src="js/modernizer.custom.js"></script>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/jquery-ui-custom.min.js"></script>
<script src="js/jquery.thumbnailScroller.js"></script>
</c:if>
<c:if test="${isgwt}">
<meta name="gwt:property" content="locale=${locale}">
<script type="text/javascript" language="javascript" src="upd/upd.nocache.js"></script>
</c:if>
<script type="text/javascript">
$(window).load(function() {
$('#slider').nivoSlider();
});
</script>
<title><c:out value="${locale}"></c:out><spring:message code="page.header" /></title>
</head>
<body>
<c:choose>
<c:when test="${empty username}">
<div class="header_con">
<div class="header_in">
<spr:header />
<spr:login />
<div class="clear"></div>
</div>
<div class="main_con">
<jsp:doBody />
<spr:footer />
</div>
<div class="clear"></div>
</div>
</c:when>
<c:otherwise>
<div id="mainHolder">
<div id="wrapper">
<spr:headerInner />
<iframe src="javascript:''" id="__gwt_historyFrame" tabIndex='-1'
style="position: absolute; width: 0; height: 0; border: 0"></iframe>
<div>
<div id="gwt_holder">
<c:if test="${isgwt}">
<div id="loader" class="loader">
</div>
</c:if>
<div id="gwt"></div>
</div>
</div>
</div>
</div>
</c:otherwise>
</c:choose>
</body>
</html>
将?locale=en
or添加?locale=kh
到 gwt url 效果很好,但只想告诉 GWT 我希望以编程方式使用此语言环境并希望它始终与该语言环境一起工作。
当我查看*.html
源代码时,我可以看到注入的<meta>
标签具有正确的locale
从SpringController
.
参考