If you don't have any experience in ResourceBundle, here is a short, 20-line example. This is a program that greets and apologizes to you in three languages.
First of all, let's set up the default properties in English, so let's create a file named a.properties with the following contents:
greetings = Hello apology = Sorry
Next, let's provide a Chinese customization in a_zh_TW.properties with UTF-8 encoding:
apology = 抱歉
I suppose you know how to edit text in UTF-8. If you don't, I recommend you to download and install NotePad++, open a new file, and select "Format -> Encoding in UTF-8", then copy and paste text from the above line.
Next, let's provide a Japanese one in a_ja_JP.properties, also in UTF-8 encoding:
greetings = こんにちは apology = すみません
Finally, let's prepare the test program in, for example, Test.java:
import net.sf.j18n.J18n;
import java.util.Locale;
import java.util.ResourceBundle;
class Test {
public static void main(String[] args) {
Locale locale;
if(args.length != 2)
locale = Locale.getDefault();
else
locale = new Locale(args[0], args[1]);
ResourceBundle bundle = J18n.getBundle("a", locale);
System.out.println(bundle.getString("greetings"));
System.out.println(bundle.getString("apology"));
}
}
To compile and run the example, try:
$ javac -encoding UTF8 -cp j18n-1.1.jar Test.java $ java -cp ".;j18n-1.1.jar" Test zh TW Hello 抱歉 $ java -cp ".;j18n-1.1.jar" Test en US Hello Sorry $ java -cp ".;j18n-1.1.jar" Test ja JP こんにちは すみません $ java -cp ".;j18n-1.1.jar" Test # when no locale is specified, your machine's default locale setting will be used. こんにちは すみません
To work with the example by yourself, download the demo source package: j18n-1.1-demo.zip
You must have JDK installed (1.5 or above).
For a detail introduction, I recommend the official Java Tutorial from java.sun.com.