Java international support (I18N problem)
1. Read the locale information of the PC.
Locale information is composed of the language and the Country Code. In Java, it provides the Locale class corresponding language information.
/** // Obtain the local information: Locale defaultLocale = Locale. getDefault (); * System. out. println ("country:" + defalocallocale. getCountry (); * System. out. println ("language:" + defaultLocale. getLanguage ());*/2. How to support internationalization
1. Add international resource files
The international resource file consists of baseName + Locale, for example, MessagesBundle_zh_CN.properties. The default international resource file name is baseName. properties. The value of a Chinese international resource file must be converted to unicode encoding. For example, k1 = \ u4F60 \ u597D, {0 }.
2. Read international resource files
// Define locale class // Locale currentLocale = new Locale ("zh", "CN"); Locale defaultLocale = Locale. getDefault (); ResourceBundle rb = ResourceBundle. getBundle ("MessagesBundle", defaultLocale); String k1 = rb. getString ("k1"); String k2 = rb. getString ("k2"); System. out. println (k1); System. out. println (k2); MessageFormat mf = new MessageFormat (rb. getString ("k1"); System. out. println (mf. format (new Object [] {"James "}));
For default placeholders, you can use MessageFormat to assign values dynamically.