Presented by @Dawei Ma
Internationalization is the process of designing an application so that it can be adapted to various languages and regions without engineering changes.
Presented by @Dawei Ma
Internationalization is the process of designing an application so that it can be adapted to various languages and regions without engineering changes.
An internationalized program has the following characteristics:
import java.util.Locale; import java.util.ResourceBundle; public class Hello { public static void main(String[] args) { String language = "en"; String country = "US"; if (args.length == 1) { language = args[0]; } else if (args.length == 2) { language = args[0]; country = args[1]; } var locale = new Locale(language, country); var messages = ResourceBundle.getBundle("messages", locale); System.out.print(messages.getString("hello") + " "); System.out.println(messages.getString("world")); } }
import java.util.Locale; import java.util.ResourceBundle; public class Hello { public static void main(String[] args) { String language = "en"; String country = "US"; if (args.length == 1) { language = args[0]; } else if (args.length == 2) { language = args[0]; country = args[1]; } var locale = new Locale(language, country); var messages = ResourceBundle.getBundle("messages", locale); System.out.print(messages.getString("hello") + " "); System.out.println(messages.getString("world")); } }
messages_en.properties
hello=Hello(en) world=World
hello=Hello(en) world=World
messages_en_US.properties
world=World(en_US)
world=World(en_US)
messages_es.properties
hello=Hola world=Mundo
hello=Hola world=Mundo
execute java
java Hello.java java Hello.java es
java Hello.java java Hello.java es
Hello(en) World(en_US) Hola Mundo
Hello(en) World(en_US) Hola Mundo
greetings = Hello farewell = Goodbye inquiry = How are you?
greetings = Hello farewell = Goodbye inquiry = How are you?
aLocale = new Locale("en","US");
aLocale = new Locale("en","US");
messages = ResourceBundle.getBundle("MessagesBundle", currentLocale);
messages = ResourceBundle.getBundle("MessagesBundle", currentLocale);
MessagesBundle_en_US.properties MessagesBundle_fr_FR.properties MessagesBundle_de_DE.properties
MessagesBundle_en_US.properties MessagesBundle_fr_FR.properties MessagesBundle_de_DE.properties
String msg1 = messages.getString("greetings");
String msg1 = messages.getString("greetings");
How does an internationalized program identify the appropriate language and region of its end users?
It references a Locale object.
Locale is the user-specific location and cultural information managed by a computer. (RFC6365)
A concept or identifier used by programmers to represent a particular collection of cultural, regional, or linguistic preferences.
langtag = language["-" script]["-" region]*("-" variant)*("-" extension)["-" privateuse]
langtag = language["-" script]["-" region]*("-" variant)*("-" extension)["-" privateuse]
How does Java get messages by locale identify?
It’s ResourceBundle!