Software Internationalization Learning

Source: Internet
Author: User

Internationalization: When the same system is visited in different countries, the language of the current country is displayed
Software internationalization: When software is developed, it is necessary to enable it to simultaneously respond to different regions and countries of the world,
And for different regions and countries to visit, to provide appropriate, in line with the visitors ' reading habits of the page or data.

Internationalization is also referred to as I18n:internationalization

Features of software internationalization:
For static text data that is used in a program, such as text elements used in menu bars, navigation bars, etc., or error messages,
status information, etc., according to the region and country of the visitor, select the text of different language to serve.
For data generated dynamically by the program, for example (date, currency, etc.), the software should be able to be displayed according to the cultural habits of the country or region in which it is currently located.
Note: A qualified internationalization software must contain both static data and the internationalization of dynamic data.

How to achieve internationalization
Internationalization is divided into static data internationalization and dynamic text internationalization
Data internationalization at rest:
The Web site displays a hint of the internationalization of fixed text, such as user name and password.
Dynamic text internationalization: units that display currency as time
1. Storing specific strings in the software
The fixed text information such as menu bar, navigation bar, error message, status information in the software can be written in a properties file.
and write different properties files according to different countries. This set of properties files is called a resource bundle
A ResourceBundle class is provided in Javaapi to describe a resource bundle, and the ResourceBundle class provides the appropriate method Getbundle,
This method can be displayed automatically according to the corresponding resource file in the country area of the visitor.


International file (properties) naming: The basic name _ language abbreviation _ country abbreviation can not write
Each resource file in a resource bundle must have a common base name. In addition to the base name, the name of each resource file must also have an additional part that identifies its local information. For example: the base name of a resource bundle is "myproperties",
The resource file name corresponding to the Chinese and English environment is: "Myproperites_zh.properties" "Myproperites_en.properties"

Each resource bundle should have a default resource file that does not have an additional part that identifies the local information. If the ResourceBundle object cannot find a resource file in the resource bundle that matches the user, it will select the resource bundle
The resource file that is closest to the user, if it is not found again, uses the default resource file. Example: Myproperites.properties

The contents of the resource file are usually in the form of "keyword = value", and the software is displayed on the page based on the keyword search value. The keywords for all resource files in a resource bundle must be the same,
The value is the text of the corresponding country. and the resource file is in the properties format file, so all the characters in the file must be ASCII loadline, for like Chinese
Such non-acsii characters must be encoded first. (Java provides a NATIVE2ASCII command for encoding). Example: Property file is not saved in Chinese
Username=username username=\u7528\u6237\u540d
Password=password password=\u5bc6\u7801
Submit=submit SUBMIT=\U63D0\U4EA4
Resource_en.properties file Resource_zh.properties File
The ResourceBundle class provides a static method getbundle that is used to mount the resource file and create an ResourceBundle instance:
Locale Currentlocale = Locale.getdefault ();
ResourceBundle MyResources =
Resourcebundle.getbundle (basename, Currentlocale);
BaseName is the resource packet name (and must be the full path).
If the resource matches the locale object, the Bun class cannot be found. In general, the default resource file is selected for display.
After the resource file is loaded, the program can invoke the GetString method of the ResourceBundle instance object to get the value corresponding to the specified resource information name.
String value = myresources.getstring ("key");
Achieving the internationalization of fixed text in Web applications
<fmt:setLocale> tags are used to set the user's localization information to be displayed in a JSP page, and local information about the settings is saved in a web domain as a locale object
Syntax: <fmt:setlocale value= "Locale"
[variant= "Variant"]
[scope=] {page|request. } "]/>
The <fmt:setBundle> tag is used to create a resource bundle (ResourceBundle) instance object based on the localization information of the <fmt:setLocale> tag settings and bind it to the properties of a web domain.
Syntax: <fmt:setbundle basename= "basename"
[var= "VarName"]
[scope= "{page|request|session|application}"]/>


2. Know what language the browser is currently using
Java provides a localized object that encapsulates information such as the current country, language, and environment that are already economic

The local language used by the browser can be obtained through the request.getlocal () method


The Java.util.Local class provides a dynamic, internationalized package
This class provides a constant for the abbreviation that represents the country names of countries
Locale locale = locale.china;//simulation of Chinese language environment
Locale.getcountry ();//Obtain the abbreviation of the country
Locale.getdisplaycountry ();//Country name
Locale.getlanguage ();//Obtain the abbreviation for the language used in the country
Locale.getdisplaylanguage ();//Get country-Used Languages

Software Internationalization Learning

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.