Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSF FacesMessage localization

My problem now is that I can't get localization working with FacesMessage

I've tried:

try {
    ResourceBundle bundle = ResourceBundle.getBundle("translations", context.getViewRoot().getLocale());
    text = bundle.getString("loginFail");
} catch (Exception e) {
    System.out.println("EXCEPTION: " + e);
}

FacesContext.getCurrentInstance().addMessage("", new FacesMessage(text));

but the following exception is thrown

java.util.MissingResourceException: Can't find bundle for base name translations, locale cs

faces-config.xml contains:

<application>
    <locale-config>
        <default-locale>cs</default-locale>
        <supported-locale>en</supported-locale>
    </locale-config>
    <resource-bundle>
        <base-name>tr.translations</base-name>
        <var>txt</var>
    </resource-bundle>
    <message-bundle>
        tr.translations
    </message-bundle>
</application>

Files translations_cs.properties and translations_en.properties are in the tr package, the location is definitely ok.

Do you have any idea how to get it working? Thanks in advance

like image 929
El_w Avatar asked Nov 27 '10 14:11

El_w


1 Answers

The basename in getBundle() should be tr.translations, exactly as you have in faces-config.xml.

like image 173
BalusC Avatar answered Oct 21 '22 01:10

BalusC