The following sections contain information about the WebLogic Server utilities used for internationalization and localization:
WebLogic Server provides three internationalization utilities:
Notes: | 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 use Localizers
to access text data. You configure the applications with Logger
and TextFormatter
classes generated from the weblogic.i18ngen
utility.
For more information on Logger
and TextFormatter
classes, see TextFormatter Class Reference for WebLogic Server, and Logger Class Reference for WebLogic Server.
The generated Logger
classes are used for logging purposes, as opposed to 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 the MyUtilLog.xml
catalog, the class, programs.utils.MyUtilLogger.class
, would be 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 7-1 is generated.
package my.text;
public class xyzTextFormatter
{
. . .
public String getErrorNumber(int err)
{
. . .
}
}
Listing 7-2 shows an example of how the getErrorNumber
method could be used in code.
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
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.
For example: targetdirectory
\i18n_user.properties
BEA Systems 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
] [filelist
]
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 file list. 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.l10ngen -d $CLASSESDIR $SRC\weblogic\msgcat
This command generates localized resources for all locales defined in the weblogic\msgcat
subdirectories.
java weblogic.l10ngen [options
] [filelist
]
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 be two variants used to further qualify the locale. In this case, the variants are separated with an underscore (for example, Traditional_Mac
as opposed to 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.l10ngen -d $CLASSESEDIR |
java weblogic.l10ngen -d $CLASSESEDIR -language zh -country TW
|
java weblogic.l10ngen -d $CLASSESEDIR -language zh |
java weblogic.l10ngen -d $CLASSESEDIR |
Note: | Example 2 is a subset of example 3. All Chinese (zh ) would include any country designations (for example, TW ) and variants. |
Note: | 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
.