You should externalize translatable strings within Java Servlets and JSP pages into Java resource bundles so that these resource bundles can be translated independent of the Java code. After translation, the resource bundles carry the same base class names as the English bundles, but with the Java locale name as the suffix. You should place the bundles in the same directory as the English resource bundles for the Java resource bundle look-up mechanism to function properly.
Because the user locale is not fixed in multilingual applications, they should call the getBundle
method by explicitly specifying a Java locale object that corresponds to the user locale. The Java locale object is called user_locale
in the following example:
ResourceBundle rb = ResourceBundle.getBundle("resource", user_locale); String helloStr = rb.getString("hello");
The above code will retrieve the localized version of the text string, hello
, from the resource bundle corresponding to the desired locale of the user.
See Also:
For more information about creating resource bundles in Java, refer to Localizing Text on JSP Pages in JDeveloper.