Internationalization of JSF 2.0

I have an application in witch I'm trying to set internationalization accessibility.

These are 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 properties files:

application_lt.properties
application_en.properties
application_de.properties

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;
    }
}

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 the locale, I use 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 determined that my default locale is "lt": lt. Why at startup my application text values ​​are loaded from application_en.properties and not from application_lt.properties?

The second problem:

commandLink, , . , , , application_en.properties. , - ...

?

+3
2

, - "lt": lt. application_en.properties, application_lt.properties?

-, , locale en Accept-Language. JSF , . .


commandLink, , . , , , application_en.properties. , - .

, . . , LocaleBean <f:view> , , .

<f:view locale="#{localeBean.lang}">

. :

+4

, JSF HTTP-Accept-Language . ( -Graph-config), HTTP .. , faces-config.xml . , faces-config.xml .

, , Accept-Language HTTP.

. , , . question, , .

+1

All Articles