Update: JPDF2HTM5 has been rebranded as BuildVu and JPDFForms has been rebranded as FormVu

Java Internationalization, it’s too easy not to do it.

One of my favourite features is how easy Java makes a number of tasks – so that I can focus on the hardcore coding problems rather than tedious ‘admin’ issues. One of these is the way it allows you to setup so that your application can display languages according to the language of the user.

It is incredibly easy to setup your java application so that all the various component texts  and messages can be swapped out for the correct language on start up. It can also automatically set currency symbols and even text orientations.

Java allows you to replace messages with tokens which can easily be replaced with the version appropriate for the user. Our JPedal PDF library uses the Messages class to support some languages whilst leaving the option for unsupported languages to be added by our users to fit their needs. You can have a default if you do not happen to be fluent in all languages…

The possible values are very easy to setup – just a folder containing text files for the various languages we have support for and load this folder into a resource bundle. Once we have loaded the resource bundle into the Messages class we load the keys and messages for the current locale into a map.

Now every time we require a components text or a message to the user we just need to make a call to Messages.getMessage(String key). The returned String is the text for the given component or message for the current Locale determined by the Java runtime.

The files used by the resource bundle are set to default to english if a file for the current locale is not set. If the user should want to support a certain locale or language they need only to copy an existing file from org/jpedal/international and add new text for each key. The advantages of having these files set up mean that once these classes are setup they are universal utilites that can easily be moved to other applications.

What is your favourite language feature in Java?

Related Posts:

The following two tabs change content below.
Kieran France is a programmer for IDRSolutions. He enjoys tinkering with most things including gadgets, code and electronics. He spends his time working on the the JPedal library and our internal test suite..
KieranF

About Kieran France

Kieran France is a programmer for IDRSolutions. He enjoys tinkering with most things including gadgets, code and electronics. He spends his time working on the the JPedal library and our internal test suite..

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>