JSF Internalization / Localization problem: Can't find bundle for base name

I was working on a JSF web application with internalization support for Turkish and English.

Usual way of implementing i18n in JSF is something similar to this

First in faces-config.xml you define locales and bundles:

    <application>
        <locale-config>
            <default-locale>tr</default-locale>
            <supported-locale>en</supported-locale>
        </locale-config>
        <resource-bundle>
            <base-name>com.example.mybundle</base-name>
            <var>i18n</var>
        </resource-bundle>
    </application>


and you put bundle files for each supported locale under the package mentioned above (com.example) and the name of the bundle files are also given as mybundle. English is default locale so you don't need to declare it but for every other locale you either append the language name or the locale name to this base name.


and instead of using "Yes"






you give the label of "Yes" which is i18n.yes in this case






i18n is the variable name we mentioned above in faces-config.xml


and then define the translations for each label in the locales individual bundle file like

yes=Yes in mybundle_en.properties

and

yes=Evet in mybundle_tr.properties

This setup was working fine until suddenly I started to receive the below error

Caused by: java.util.MissingResourceException: Can't find bundle for base name com.example.mybundle, locale tr

It took me a while untile I realized that it was because I was using special Turkish characters in it like 'Ç'. In fact the properties file editor in Eclipse IDE is good at automatically converting those kind of special letters into their unicode counter parts as I type them but I was entering them in source editor not properties editor so they went in as ASCII letters so resource bundle loader could not parse it.

Another solution to this problem is saving the file as UTF-8 instead of ASCII. This way you don't have to convert special letters to unicode code points.

Nevertheless the error message should be more relevant I think.

Yorumlar

Popüler Yayınlar