[brailleblaster] Re: Localizing with PropertyResourceBundle

  • From: Michael Whapples <mwhapples@xxxxxxx>
  • To: brailleblaster@xxxxxxxxxxxxx
  • Date: Sat, 04 Dec 2010 16:19:47 +0000

Hello,
Here is the answer to how to get it loaded, it also supports falling back to more and more general forms should a suitable locale not be supported. NOTE: This is a great example of polymorphism as the same call will also load a suitable ResourceBundle class should you have one for the locale, but if no suitable class is present then a properties file is looked for and used if found and the rest of the application need not know how the resource bundle was got.

In short you want to look at the JDK documentation for ResourceBundle.getBundle calls (there are a few options). You would do best to read that documentation as to the order of how things are chosen, its more lengthy than I want to type out. The two main ones of interest I think are:
public static ResourceBundle getBundle(String baseName)
public static ResourceBundle getBundle(String baseName, Locale locale)

You probably only want to use the ones with ClassLoaders if you want it to be loaded from another location than the main BrailleBlaster jar file.

Michael Whapples
On 04/12/10 02:47, John J. Boyer wrote:
The tutorial does not discuss PropertyResourceBundle. I'm having a bit
of trouble understanding the source code. You are supposed to call the
constructor with a Reader type, but Readir is an abstract class, and the
user is supposed to implement certain methods. How can this be? How do I
tell propertyResourceBundle to read a file?

Do the names of the properties files have to conform to a certain
format, like blastlocale_en_GB.properties

How are characters outside the usual "printable" range represented? For
example how would a Hebrew letter be represented in the value of a key?
How are different encodings handled?

I want to encapsulate all the localization code within one package, so
the locale can be specified in a setup routine and when we want to
assign a string to a label or mesage we can just call a simple method
with the key. I know from experience that unless one gets in the habit
of using such a technique in the beginning it is very difficult to apply
it later.

John



Other related posts: