Using Localized Text
Automatic translation of numbers and dates into the local language is a great help, but until automatic translation software is a lot smarter than it is today, you have to translate all the text used in the application yourself. A set of Java classes can help you pick the right version for a specific locale.
The main class for dealing with localized resources (such as text,
images, and sounds) is named
java.util.ResourceBundle
.
This class is actually the abstract superclass for the two subclasses
that do the real work,
ListResourceBundle and
PropertyResourceBundle,
but it provides methods that let you get an appropriate subclass
instance, hiding the details about which subclass actually provides
the resources. Details about the difference between these two
subclasses are beyond the scope of this book. Suffice it to say that
the JSTL actions can use resources provided through either of them.
For most web applications, an instance of the
PropertyResourceBundle is used. A
PropertyResourceBundle instance is associated with
a named set of localized text resources; a key identifies each
resource. The keys and their corresponding text values
are stored in a regular text file, known as a
resource
bundle
file:
site_name=The Big Corporation Inc. company_logo=/images/logo_en.gif welcome_msg=Hello!
Here three keys, site_name,
company_logo, and welcome_msg, have been assigned values. The key is a string, without space or other special characters, and the value is any text. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access