我面临着本地化的奇怪行为。我的应用程序中有两种语言 - 英语和斯洛伐克语。在我当地的Glassfish切换区域工作完美。但部署在Jelastic Glassfish上的相同应用程序始终使用英语。切换区域设置不起作用。我已经调试了远程app和facescontext(FacesContext.getCurrentInstance()。getViewRoot()。getLocale()和FacesContext.getCurrentInstance()。getExternalContext()。getRequestLocale())返回正确的sk语言环境,但页面仍然是用英语讲。在语言菜单中选择了斯洛伐克(第二选项)!
两条Glassfishes都在版本3.1.2.2中,Mojarra 2.2.7和Primefaces 5.0在JDK7上运行。本地GF在Win7上运行,远程在Linux上运行(CentOS?)并且它是集群的(也许这就是原因?)
面-conf.xml中
<locale-config>
<default-locale>en</default-locale>
<supported-locale>sk</supported-locale>
</locale-config>
<resource-bundle>
<base-name>Bundle</base-name>
<var>bundle</var>
</resource-bundle>
login.xhtml
<f:view locale="#{loginBean.locale}">
...
<p:outputLabel value="#{bundle.language}: "/>
<p:selectOneMenu value="#{loginBean.language}" id="loginLocale">
<f:selectItem itemValue="en" itemLabel="English" />
<f:selectItem itemValue="sk" itemLabel="Slovensky" />
<p:ajax update="@all"/>
</p:selectOneMenu>
...
</f:view>
LoginBean.java
@ManagedBean(name = "loginBean")
@SessionScoped
public class LoginBean implements Serializable{
private Locale locale = FacesContext.getCurrentInstance().getExternalContext().getRequestLocale();
...
public Locale getLocale() {
return locale;
}
public String getLanguage() {
return locale.getLanguage();
}
public void setLanguage(String language) {
locale = new Locale(language);
FacesContext.getCurrentInstance().getViewRoot().setLocale(locale);
}
}
感谢您的帮助
米甲
答案 0 :(得分:1)
我找到了解决方案,但我不确定,为什么会这样。我的slovak捆绑文件的名称是Bundle_sk_SK.properties,我已将其重命名为Bundle_sk.properties,现在它可以正常工作。
米甲