Internationalization support for Java (i18n issues)

Source: Internet
Author: User


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)

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.