"Turn" Java.util.ResourceBundle use detailed

Source: Internet
Author: User
Tags custom name

original link: http://lavasoft.blog.51cto.com/62575/184605/They write too well, clear and accurate. I. Knowledge of international resource documentsThis class provides a shortcut to software internationalization. This class allows you to write a program that:easily localize or translate to different languagesworking with multiple locales at oncecan be easily modified in the future to support more language environments simply put, the function of this class is to read the resource properties file Then, depending on the name information (localization information) of the. properties file, match the country language information for the current system (or program-specified), and then get the contents of the corresponding properties file.  One thing to note about using this class is that the name of the properties file is canonical: The generic naming convention is: Custom Name _ language code _ Country code. Properties, if it is the default, write directly as: custom name. Properties For example:myres_en_us.properties
myres_zh_cn.propertiesmyres.propertieswhen the Chinese operating system, if the myres_zh_cn.properties, myres.properties two files are present, the priority is to use myres_zh_cn.properties, when Myres_zh_ Cn.properties does not exist, the default myres.properties is used.  resource files that do not provide a language and region are the system default resource files. resource files must be iso-8859-1 encoded, so for all non-western language processing, they must first be converted to the Java Unicode escape format. The conversion method is a tool that comes with the JDK native2ascii. Second, examples define three resource files to be placed below the root of SRC (this must be the case, or you will be placed under your own calsspath. myres.propertiesAaa=good
Bbb=thanks
myres_en_us.propertiesAaa=good
Bbb=thanks
myres_zh_cn.propertiesaaa=\u597d
BBB=\U591A\U8C22 ImportJava.util.Locale;
ImportJava.util.ResourceBundle;

/**
* International Resource Binding Test
*
* @author leizhimin 2009-7-29 21:17:42
*/
PublicclassTestresourcebundle {
PublicStaticvoidMain (string[] args) {
Locale Locale1 =NewLocale ("en","CN");
ResourceBundle resb1 = Resourcebundle.getbundle ("Myres", Locale1);
System.out.println (Resb1.getstring ("AAA"));

ResourceBundle RESB2 = Resourcebundle.getbundle ("Myres", Locale.getdefault ());
System.out.println (Resb1.getstring ("AAA"));

                locale Locale3 = New Locale ("en", "US");
ResourceBundle RESB3 = Resourcebundle.getbundle ("Myres", Locale3);
System.out.println (resb3.getstring ("AAA"));
}
} Operation Result:Good
Good
Good

Process finished with exit code 0 If the default locale is used, the Myres_en_us.properties or myres.properties resource file is selected on the English operating system. third, recognize the locale
The Locale object represents a specific geographical, political, and cultural area. Actions that require locale to perform their tasks are called locale-sensitive operations that use locale to tailor information to users. For example, displaying a numeric value is a locale-sensitive operation that should be formatted according to the custom/tradition of the user's country, region, or culture.  Use the construction methods in this class to create the Locale:Locale (String language)
Locale (String language, String country)
Locale (String language, String country, string variant) Once you have created the Locale, you can query information about itself. ISO country codes can be obtained using getcountry, and ISO language codes are obtained using GetLanguage. You can use Getdisplaycountry to get the country name that is appropriate for displaying to the user. Similarly, you can use Getdisplaylanguage to get the language name that is appropriate for displaying to the user. Interestingly, the Getdisplayxxx method itself is locale-sensitive, with two versions: one using the default locale as the parameter and the other using the specified locale as the parameter.
The language parameter is a valid ISO language code. These codes are lowercase two-letter codes defined by ISO-639. A complete list of these codes can be found on many sites, such as: 
Http://www.loc.gov/standards/iso639-2/englangn.html.
The national parameter is a valid ISO country code. These codes are uppercase two-letter codes defined by ISO-3166. A complete list of these codes can be found on many sites, such as:
http://www.iso.ch/iso/en/prods-services/iso3166ma/02iso-3166-code-lists/list-en1.html.
iv. transcoding Native2ascii of Chinese resource documentsThis tool uses the following:If you feel trouble, you can paste the Chinese into the inside, enter can see the result of transcoding. to understand this, it is not uncommon for the internationalization of web frameworks such as struts.

"Turn" Java.util.ResourceBundle use detailed

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.