beautypg.com

BEA WebLogic Server User Manual

Page 81

background image

Example of an Application Using a TextFormatter Class

Internationalization Guide

D-5

* using the catalog editing utility,
weblogic.i18ntools.gui.MessageEditor.
*


*


* English(base language) ../msgcat/Helloworld.xml
* French ../msgcat/fr/FR/HelloWorld.xml
*

*


* To build this example run the bld.sh(UNIX) or bld.cmd (NT)
scripts from
* the examples/i18n/simple directory. CLIENT_CLASSES must be set
up and
* needs to be in the classpath when running the example.
*/

public final class HelloWorld {

public static void main(String[] argv) {
/*
* The easiest method for displaying localized text is to
* instantiate the generated formatter class for the HelloWorld
catalog.
* This class contains convenience methods that return localized
text for
* each message defined in the catalog. The class name is
* the catalog name followed by "TextFormatter".
*
* Normally, one would use the default constructor to obtain
* formatting in the current locale. In this example we'll use
a locale
* based on arguments to construct the TextFormatter.
*/
Locale lcl;
if (argv.length == 0) { // default is default locale for JVM
lcl = Locale.getDefault();
}
else {
String lang = null;
String country = null;
//get the language code
lang = argv[0];
if (argv.length >= 2) { // get the country code
country = argv[1];
}
lcl = new Locale(lang,country);
}
/*
* get formatter in appropriate locale