[Javase entry series] Chapter 19th _ internationalization of applications

Source: Internet
Author: User
Tags i18n
Chapter 4 internationalization of applications-v512 workshop Editor: Xuan Yu
Resource Package Message formatting Internationalization and Localization My blog V512 Studio Chinese Emy of Sciences

Internationalization and Localization
Overview: internationalization (i18n) indicates that a product or service can adapt to the requirements of different countries and regions, including the language type, that is, to achieve the universality of products or services.
Localization (l10n) refers to manufacturing or transforming existing products and services for a specific region (including language and culture)
Analysis: Since there are exactly 18 English letters between the start and end letters, people also like to refer to i18n for short.
Local users can use their own languages (including cultural habits or expressions) to easily interact with localized products.
In the simplest way, the information visible to all users conforms to the local language and cultural habits. More importantly, localized products must comply with the laws or other regulations of the region.
It can be said that internationalization is the goal, and products are expected to be widely used, while localization is the specific manifestation of internationalization, or the specific implementation method.
Only after localized processing of a product in multiple regions can this product be said to be an international product or provide international support.
For example, a product that only provides an English label description can be labeled differently for different languages in different countries and regions for international purposes.
The process of adding different labels and selling them in different countries can be considered as an International Product localization process in a specific region.
Objective: To compile code that can run normally (with localized appearance) in any supported region settings
Encoding: Since each character in Unicode encoding has a basic unified representation, Unicode encoding is used in international programs to save text information related to user interaction.
This is to avoid the default encoding methods used by systems in different countries and regions, and may cause character encoding conversion problems. Therefore, unified unicode encoding is adopted.
The latest unicode encoding standard is unicode5.0. Its standards are coordinated and modified by the International Standardization Organization and a federation of large IT companies.
Focus: language, digital format, time/date format, currency, ID card/social security number/passport, phone number/address/zip code, weights, taboos, names and titles
Summary: currently, the mainstream solution for internationalization or localization of programs is to save the resource information that requires internationalization or localization in the resource package separately.
No matter which system environment the program runs, it searches for matching attribute files or resource binding classes in the resource package for the current system environment.
Then, use the resource package name to match the resource package. The purpose is to extract the localized information and then explicitly present it to the user.
So as long as different countries and regions are added with different resource packages, they can all be processed locally. The source code does not need to be changed.

 

 

 

Resource Package
Overview: In international applications, resources related to the runtime environment are usually stored in the resource bundle form, that is, information to be processed internationally.
Such as message text, menus, and button labels. Each resource package corresponds to a User Locale
Name: <package name >_< language code> for example, mylabels_en
<Package name >_< language code >_< country code> for example, myres_zh_cn
You can choose ie-tools-Internet option-language-add-to view the language code of each country.
Format: Property file and resource bundle class)
Property file: used to save the string information to be internationalized. A plain text file with the same name as the resource package prefix and suffix ". properties"
The format of the property file is the same as that of the previous system property export file. For details, see section 14.4.2 of the javase entity book.
The Java. util. resourcebundle class can be used to load attribute files and read resources. In fact, it uses a subclass
Resource binding class: another form of resource package, which corresponds to the property file. Each resource binding class corresponds to a different User Locale
The resource binding class should have the same name as the resource package, which stores the international "key-value" attribute information, but the information format is not limited to the string type.
Inheriting the abstract class java. util. listresourcebundle is the most convenient way to define the resource binding class.
This class saves all international resources in the form of an array of Two-Dimensional Objects (object [] []) and provides the function of searching for "values" by "key ".

 

 

 

Message formatting
Overview: similar to formatting numeric and date/time information using tools such as numberformat and dateformat
The Java. Text. messageformat class is provided in JDK to format text messages containing variable parameters.
Analysis: sometimes some messages may be displayed to the user, such as error messages or warnings of dangerous operations.
However, these messages may contain some uncertain text, such as displaying the user name.
This text message is relatively complex or uncertain, and can be formatted to process the message.
Term: Message mode: Message pattern is also called a message mode string or mode string. It is a string
Inside the string, the placeholder enclosed by braces {} is used to provide the message body framework.
You can use messageformat to format variable data and replace the placeholder.
Placeholder: placeholder can set optional types and styles for placeholders in the mode string for more detailed formatting.
The placeholder format is {<index >,< type >,< style>}
Conclusion: the essence of message formatting is to provide only the subject framework in the constructed message text.
Use placeholders to indicate the content that needs to be changed for different users, time, or languages.
Then you can create a messageformat object to bind it to the mode string and specify a specific locale
You can also format the parameters and replace the placeholders.
Supplement: You need to add the following knowledge points: Message formatting in international applications
Message mode strings in international programs also need to be localized. In this case, you can save them to the resource package.
To provide versions corresponding to different locale. The implementation method is the same as that for saving common text resources.

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.