Java Reference
In-Depth Information
codes, such as en for English and fr for French. 1
Using new Locale("fr")
would create a locale for French.
A resource bundle has a unique base name and multiple files, one for
each locale. When the resource bundle named MyBundle is used and
the language is French, Java automatically looks for MyBundle_fr in the
class path. If it doesn't find it, it uses MyBundle as a default.
The file can be implemented in different ways but always contains a set
of key-value pairs. The implementation that we'll use is the . properties
file; in fact, you've already seen the Stripes default resource bundle,
StripesResources.properties . In a multilingual application, you would have
resource bundle files such as the following:
StripesResources_fr.properties // French
StripesResources_es.properties // Spanish
StripesResources_it.properties // Italian
StripesResources.properties
// default (English, in our case)
Each file would contain the same keys but with values translated in the
specific language. For example, StripesResources.properties might contain
this:
greeting=Hello
and StripesResources_fr.properties would have this:
greeting=Bonjour
That's pretty simple. Now that we have the basics of locales and re-
source bundles down, let's see what we have to do in Stripes to make
the application available in French with a StripesResources_fr.properties
file. First, we need to let Stripes know about our localization plans.
Configuring the List of Supported Locales
When a request arrives at Stripes, the headers contain the list of the
user's preferred locales, as configured in their browser. Stripes com-
pares this to the list of locales supported by the application and chooses
the best match. By default, a Stripes application supports one locale:
the system's default, which is English in our case. So, the first thing
we have to do is set the list of supported locales to English and French
using the language codes.
1. See Javadocs for the java.util.Locale class for more details on language codes and the
other parameters you can use for a locale.
 
 
Search WWH ::




Custom Search