A Dark Divided Gem
A Dark Divided Gem

Reputation: 446

Java ResourceBundle changing to default language

I have created the following ResourceBundle in Java which reads from the correct MessegesBundle_en_GB.properties file:

ResourceBundle labels = 
        ResourceBundle.getBundle("MessegesBundle",new Locale( "en", "GB"));
labels.getString("Test");

However when I try using another language (Scottish Gaelic) it simply defaults back to en_GB

ResourceBundle labels = 
        ResourceBundle.getBundle("MessegesBundle",new Locale( "gd", "GB"));
system.out.println(labels.getLocale()); // returns en-GB
labels.getString("Test");

Looking through the list of Available Locales from Locale.getAvailableLocales(); and "gd" doesn't appear.

Does this mean I can't use ResourceBundle for I18N or is there a way of either adding Gaelic or forcing ResourceBundle to use the correct properties file?

Thanks

Upvotes: 1

Views: 2645

Answers (2)

nicephotog
nicephotog

Reputation: 11

The server needs to have that charset language installed to load it, I suppose you could "force" it however when serving a page but you would need to pick up information specificaly from the user as a request for that page language to be assigned.

Upvotes: 0

dcernahoschi
dcernahoschi

Reputation: 15250

The locales returned by getAvailableLocales() are not very important as you can create new ones the way you did: new Locale( "gd", "GB").

As stated in the Locale java docs the locale main purpose is to identify resources: resource bundles, number formats, etc. The strings identifying the Locale are not even validated upon creation.

My guess is that you don't have the MessegesBundle_gd_GB.properties resource available in the classpath.

Upvotes: 1

Related Questions