The internationalization program of Java Learning

Source: Internet
Author: User
Tags erro locale

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.