gpt4 book ai didi

spring - JSF2.0 国际化不适用于服务器

转载 作者:行者123 更新时间:2023-11-28 23:48:07 26 4
gpt4 key购买 nike

我使用 JSF 2.0 和 Spring 3.0.2 以及 tomcat 7.0.14.0 作为服务器。我在更改网站语言时遇到问题。所有代码在我的本地服务器上运行良好。但是当我在服务器上部署时,语言更改不会生效。它会自动选择意大利作为默认语言。当我点击另一种语言时,没有任何变化。这是我的 bean 代码:

            @ManagedBean(name="language")
@SessionScoped
public class LanguageBean implements Serializable{

private static final long serialVersionUID = 1L;

private String localeCode;





private static Map<String,Object> countries;
static{
countries = new LinkedHashMap<String,Object>();
countries.put("English", Locale.ENGLISH); //label, value

countries.put("Italian", Locale.ITALIAN);
}

public LanguageBean() {
countries = new LinkedHashMap<String,Object>();


countries.put("English", Locale.ENGLISH); //label, value
countries.put("Italian", Locale.ITALIAN);

}

public Map<String, Object> getCountriesInMap() {
return countries;
}


public String getLocaleCode() {
return localeCode;
}


public void setLocaleCode(String localeCode) {
this.localeCode = localeCode;
}


public void countryLocaleCodeChanged(ValueChangeEvent e){

String newLocaleValue = e.getNewValue().toString();


for (Map.Entry<String, Object> entry : countries.entrySet()) {
System.out.println("newLocaleValue "+newLocaleValue+"\n entry.getValue().toString()"+entry.getValue().toString());
if(entry.getValue().toString().equals(newLocaleValue)){

FacesContext.getCurrentInstance()
.getViewRoot().setLocale((Locale)entry.getValue());
FacesContext context = FacesContext.getCurrentInstance();
System.out.println("Default : "+context.getApplication().getDefaultLocale());

context.getApplication().setDefaultLocale((Locale)entry.getValue());


}
}

}

这是 config.xml::

    <locale-config>
<default-locale>en</default-locale>
</locale-config>
<resource-bundle>
<base-name>com.mad_u.welcome</base-name>
<var>msg</var>
</resource-bundle>

请给我一些想法。提前致谢。

最佳答案

我遇到了同样的问题。我的属性文件是这样的:

  • message_en_US.properties
  • message_es_ES.properties
  • message_eu_ES.properties

它在我的本地服务器上工作,但是将网络上传到我的服务器时语言更改不起作用,所以我更改了这个:

        countries.put("Castellano", new Locale("es"));
countries.put("Euskara", new Locale("eu"));
countries.put("English", new Locale("en"));

<locale-config>
<default-locale>es</default-locale>
<supported-locale>es</supported-locale>
<supported-locale>eu</supported-locale>
<supported-locale>en</supported-locale>
</locale-config>

  • message_en.properties
  • message_es.properties
  • message_eu.properties

关于spring - JSF2.0 国际化不适用于服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11737403/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com