Internationalization Guide
The following sections contain information about the WebLogic Server utilities used for internationalization and localization:
WebLogic Server provides three internationalization utilities:
Note: Text in the catalog definitions may contain formatting characters for readability (for example, end of line characters), but these are not preserved by the parsers. Text data is normalized into a one-line string. All leading and trailing white space is removed. All embedded end of line characters are replaced by spaces as required to preserve word separation. Tabs are left intact.
Note: Use escapes to embed newlines (for example '\n'). These are stored and result in newlines when printed.
Use the weblogic.i18ngen
utility to validate message catalogs and create the necessary runtime classes for producing localized messages. The weblogic.l10ngen
utility validates locale-specific catalogs, creating additional properties files for the different locales defined by the catalogs.
You can internationalize simple text-based utilities that you are running on WebLogic Server by specifying that those utilities must use Localizers
to access text data. You configure the applications with Logger
and TextFormatter
classes generated from the weblogic.i18ngen
utility.
Refer to weblogic.i18ngen Utility for detailed information about the weblogic.i18ngen
utility. For more information on Logger
and TextFormatter
classes, refer to TextFormatter Class Reference for BEA WebLogic Server, and Logger Class Reference for BEA WebLogic Server.
The generated Logger
classes are used for logging purposes instead of the traditional method of writing English text to a log. For example, weblogic.i18ngen
generates a class xyzLogger
in the appropriate package for the catalog xyz.xml
. For example, for the MyUtilLog.xml
catalog, the class programs.utils.MyUtilLogger.class
wouldbe generated. For each log message defined in the catalog, this class contains static public methods as defined by the method
attributes.
TextFormatter
classes are generated for each simple message catalog. These classes include methods for accessing localized and formatted text from the catalog. They are convenience classes that handle the interface with the message body, placeholders, and MessageFormat
. You specify the formatting methods through the method attribute in each message definition. For example, if the definition of a message in a catalog includes the attribute, method=getErrorNumber(int err)
, the TextFormatter
class shown in Listing 4-1 is generated.
Listing 4-1 Example of a TextFormatter Class
package my.text;
public class xyzTextFormatter
{
. . .
public String getErrorNumber(int err)
{
. . .
}
}
Listing 4-2 shows an example of how the getErrorNumber
method could be used in code.
Listing 4-2 Example of getErrorNumber Method
import my.text.xyzTextFormatter
. . .
xyzTextFormatter xyzL10n = new xyzTextFormatter();
System.out.println(xyzL10n.getErrorNumber(someVal));
The output prints the message text in the current locale, with the someVal
argument inserted appropriately.
Use the weblogic.i18ngen
utility to parse message catalogs (XML files) to produce Logger
and TextFormatter
classes used for localizing the text in log messages. The utility creates or updates the following properties file (which is used to load the message id lookup class hashtable weblogic.i18n.L10nLookup):
targetdirectory/i18n_user.properties
The weblogic.i18ngen
utility also creates or updates the i18n_user.properties
file. Any errors, warnings, or informational messages are sent to stderr
.
In order for user catalogs to be recognized, the i18n_user.properties file must reside in a directory identified in the WebLogic classpath.
targetdirectory/i18n_user.properties
BEA recommends that the i18n_user.properties file reside in the server classpath. If the i18n_user.properties file is in targetdirectory, then targetdirectory should be in the server classpath.
java weblogic.i18ngen [
options
]
Note: Utilities can be run from any directory, but if files are listed on the command line, then their path is relative to the current directory.
The weblogic.l10ngen
utility generates property resources for localizations of message catalogs named in the filelist. The file list identifies the top-level catalogs, not translated catalogs.
Similarly the target directory (-d option) identifies the same target directory where the default localizations reside. For example, if the default catalogs are located in $SRC/weblogic/msgcat and the generated resources are to be placed in $CLASSESDIR, the appropriate l10ngen invocation would be:
java weblogic.i18n.tools.l10ngen -d $CLASSESDIR $SRC/weblogic/msgcat
This command generates localized resources for all locales defined in the weblogic/msgcat subdirectories.
java weblogic.l10ngen [
options
]
Note: Utilities can be run from any directory, but if files are listed on the command line, then their path is relative to the current directory.
Catalog subdirectories are named after lowercase, two-letter ISO 639 language codes (for example, ja for Japanese and fr for French). You can find supported language codes in the java.util.Locale javadoc.
Variations to language codes are achievable through the use of uppercase, two-letter ISO 3166 country codes and variants, each of which are subordinate to the language code. The generic syntax is lang/country/variant.
For example, zh is the language code for Chinese. CN is a country code for simplified Chinese, whereas TW is the country code for traditional Chinese. Therefore zh/CN and zh/TW are two distinct locales for Chinese.
Variants are of use when, for instance, there is a functional difference in platform vendor handling of specific locales. Examples of vendor variants are WIN, MAC and POSIX. There may actually be two variants used to further qualify the locale. In this case, the variants are separated with an underscore (for example, Traditional_Mac vs. Modern_MAC).
Note: Language, country and variants are all case sensitive.
A fully-qualified locale would look like zh/TW/WIN, identifying traditional Chinese on a Win32 platform.
Message catalogs to support the above locale would involve the following files:
Specific localizations do not need to cover all messages defined in parent localizations.
java weblogic.i18ntools.l10ngen -d $CLASSESEDIR catalogdirectory
java weblogic.i18ntools.l10ngen -d $CLASSESEDIR -language zh -country TW catalogdirectory
java weblogic.i18ntools.l10ngen -d $CLASSESEDIR -language zh catalogdirectory
java weblogic.i18ntools.l10ngen -d $CLASSESEDIR catalogdirectory
Note: Example 2 is a subset of example 3. All Chinese (zh) would include any country designations (for example, TW) and variants.
weblogic.l10ngen does not validate the locale designators (language, country, variant).
The weblogic.GetMessage utility replaces the CatInfo utility provided with earlier releases of WebLogic Server. This utility displays message content but can also be used to list all or some subset of installed messages. By default (no options), weblogic.GetMessage prints a usage statement.
java weblogic.GetMessage [
options
]
Note: All options may be abbreviated to a single character except -verbose.
If no arguments are provided, weblogic.GetMessage outputs a usage message, equivalent to -help
.