Java.util.ResourceBundle use of the detailed

Source: Internet
Author: User
Tags locale custom name

I. Knowledge of international resource documentsThis class provides a shortcut to software internationalization. This class allows you to write programs that can easily be localized or translated into different languages once processing multiple locales can be easily modified to support the more simple point of the language environment, the role of this class is to read the resource properties file (Propert ies), and then, depending on the name information (localization information) of the. properties file, match the country language information for the current system (or you can specify the program), 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. PropertiesFor example: when the Chinese operating system, if the, two files are present, priority will be used Myres_, the default is used when does not exist. 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 native2ascii with the tool that comes with the JDK. Second, examplesDefine 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=thanksmyres_en_us.propertiesaaa=good bbb=thanksmyres_zh_cn.propertiesaaa=\u597d bbb= \u591a\u8c22
ImportJava.util.Locale;ImportJava.util.ResourceBundle;/*** International Resource binding Test * *@authorleizhimin 2009-7-29 21:17:42*/  Public classTestresourcebundle { Public Static voidMain (string[] args) {Locale locale1=NewLocale ("zh", "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=NewLocale ("en", "US"); ResourceBundle RESB3= Resourcebundle.getbundle ("Myres", Locale3); System.out.println (Resb3.getstring ("AAA")); } }
Operation Result:

Process finished with exit code 0
If the default locale is used, the or 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 method in this class to create Locale:locale (String language)
Locale (String language, String country)
When the locale (string language, String country, string variant) is created, the locale can be queried for 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:
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:// iv. transcoding Native2ascii of Chinese resource documentsThe use of this tool is as follows: If you feel trouble, you can paste the Chinese into the inside, enter can see the results after transcoding. To understand this, it is not uncommon for the internationalization of web frameworks such as struts. This article transferred from:

Java.util.ResourceBundle use of the detailed

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: 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.