国际化后

原文: https://docs.oracle.com/javase/tutorial/i18n/intro/after.html

国际化计划的源代码如下。请注意,消息的文本不是硬编码的。

  1. import java.util.*;
  2. public class I18NSample {
  3. static public void main(String[] args) {
  4. String language;
  5. String country;
  6. if (args.length != 2) {
  7. language = new String("en");
  8. country = new String("US");
  9. } else {
  10. language = new String(args[0]);
  11. country = new String(args[1]);
  12. }
  13. Locale currentLocale;
  14. ResourceBundle messages;
  15. currentLocale = new Locale(language, country);
  16. messages = ResourceBundle.getBundle("MessagesBundle", currentLocale);
  17. System.out.println(messages.getString("greetings"));
  18. System.out.println(messages.getString("inquiry"));
  19. System.out.println(messages.getString("farewell"));
  20. }
  21. }

要编译和运行此程序,您需要以下源文件: