Internationalization program is the language of the program according to the user's language display, each country users can read
The implementation method is to write the output text in the configuration file, and then according to the user system language to choose different language output
1 Packagecom.gh;2 3 ImportJava.text.MessageFormat;4 ImportJava.util.Locale;5 ImportJava.util.ResourceBundle;6 ImportJava.util.Scanner;7 /**8 * Internationalization Procedure9 * Change output language with config fileTen * @authorGanhang One * A */ - Public classDome { - Public Static voidMain (string[] args) { the //Instantiate locale -Locale locale =Locale.getdefault (); - //configuration file and locale bindings -ResourceBundle res = resourcebundle.getbundle ("Com.gh.info", locale); +Scanner sc =NewScanner (system.in); -String Usenamekey = res.getstring ("Usename"); +String Passwordkey = res.getstring ("Password"); AString inputkey = res.getstring ("Input"); atString infosuccess = res.getstring ("info.success"); -String Infoerro = res.getstring ("Info.erro"); -System.out.println (Inputkey +usenamekey); -String username =Sc.next (); -System.out.println (Inputkey +passwordkey); -String pwd =Sc.next (); in if("admin". Equals (username) && "123". Equals (PWD) { -String info =Messageformat.format (infosuccess,username); to System.out.println (info); + } - Else the System.out.println (Infoerro); * } $}
Configuration file
Info_zh_cn.properties
usename=\u7528\u6237\u540dpassword=\u5bc6\u7801input=\u8bf7\u8f93\u5165info.success=\u767b\u5f55\u6210\u529f\ Uff0c{0}info.erro=\u7528\u6237\u540d\u6216\u5bc6\u7801\u9519\u8bef
The internationalization program of Java Learning