I have an application in witch I am trying to set a internationalization availability.
This is my faces-config.xml:
<application>
<locale-config>
<default-locale>lt</default-locale>
<supported-locale>en</supported-locale>
<supported-locale>de</supported-locale>
</locale-config>
<resource-bundle>
<base-name>application</base-name>
<var>msg</var>
</resource-bundle>
</application>
I have three property files:
application_lt.properties
application_en.properties
application_de.properties
The bean class:
@ManagedBean(name = Beans.LOCALE_BEAN)
@SessionScoped
public class LocaleBean extends BaseBean implements Serializable {
private String lang;
public String getLang() {
return lang;
}
public void setLang(String lang) {
this.lang = lang;
}
}
The action class:
@ManagedBean(name = "localeAction")
@SessionScoped
public class LocaleAction extends BaseAction implements Serializable {
public void changeLocale() {
LocaleBean localeBean = getBean(Beans.LOCALE_BEAN);
String language = localeBean.getLang();
FacesContext.getCurrentInstance().getViewRoot().setLocale(new Locale(language));
}
}
To change locale I am using commandLink:
<h:commandLink action="#{localeAction.changeLocale}">
<f:setPropertyActionListener target="#{localeBean.lang}" value="en"/>
English
</h:commandLink>
<h:commandLink action="#{localeAction.changeLocale}">
<f:setPropertyActionListener target="#{localeBean.lang}" value="lt"/>
Lithuanian
</h:commandLink>
First problem:
I have defined that my default locale is "lt": lt. Why when I start up my application text values is loaded from application_en.properties and not from application_lt.properties?
Second problem:
When I execute commandLink action, the locale changes depending on which locale I have selected. But executing the action was one click, the second click on any other link of application is OK as well and when I click on any link of application for a third time, the text values are locaded from application_en.properties. It seems that locale changes somehow...
Any ideas?