Exemples: internationalization
GetLocales.java
import java.util.*;
import java.text.*;
public class GetLocales{
static public void main(String[] args) {
Locale list[] = DateFormat.getAvailableLocales();
for (int i = 0; i < list.length; i++) {
System.out.print(list[i].toString());
int l = list[i].toString().length();
while (l++<7) System.out.print(" ");
System.out.println(list[i].getDisplayName());
}
}
}
I18NSample.java
import java.util.*;
public class I18NSample {
static public void main(String[] args) {
String language;
String country;
if (args.length != 2) {
language = new String("en");
country = new String("US");
} else {
language = new String(args[0]);
country = new String(args[1]);
}
Locale currentLocale;
ResourceBundle messages;
currentLocale = new Locale(language, country);
messages = ResourceBundle.getBundle("MessagesBundle",
currentLocale);
System.out.println(messages.getString("greetings"));
System.out.println(messages.getString("inquiry"));
System.out.println(messages.getString("farewell"));
}
}
MessageBundle_en_US.properties
greetings = Hello.
farewell = Goodbye.
inquiry = How are you?
MessageBundle_fr_FR.properties
greetings = Bonjour.
farewell = Au revoir.
inquiry = Comment allez-vous?
Last modified: Thu Dec 8 12:48:15 EST 2005
par Douglas Eck [douglas D0T eck AT umontreal D0T ca]