One, read the locale information of the PC
Locale information is made up of language and country code, and in Java, the locale class corresponds to the language information.
/* *//Get local information Locale Defaultlocale = Locale.getdefault (); * SYSTEM.OUT.PRINTLN ("Country:" + defaultlocale.getcountry ()); * SYSTEM.OUT.PRINTLN ("language:" + defaultlocale.getlanguage ()); */
two, how to support internationalization
1. Accession to the International Resource document
The internationalized resource file is composed of Basename+locale, for example: Messagesbundle_zh_cn.properties. The default internationalized resource file name is called Basename.properties. The internationalized resource file for Chinese must convert the value in the file to Unicode encoding. For example: k1=\u4f60\u597d,{0}.
2. Read the internationalized resource file
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[] {"Zhang San"});
For the default placeholder, you can use the Messageformat assignment dynamically.
Internationalization support for Java (i18n issues)