The realization of resource localization in analytic asp.net

Source: Internet
Author: User
Tags datetime

A Basic concepts

1. Why do you want to localize your resources?

Our site may be for people in various countries and regions around the world to browse, each country and region of people have their own language and cultural characteristics. Take our great motherland for example, Chinese mainland in Simplified Chinese, Hong Kong and Macao are using traditional Chinese. Other countries for money, numbers, calendars and other forms of expression of information are different, our country more use the format of the year, and the United States is the month of the day. There are so many different things, and I don't have a lot of examples. In order to give our site visitors a better user experience, we should provide a global solution, as long as users choose his language and region, the site according to his language and cultural habits to show the page information, this process can be called localization.

2. Culture, invariant culture, neutral culture, specific culture

The culture name follows the RFC 1766 standard, and the format is "<languagecode2>-<country/regioncode2>", where <languagecode2> is from ISO 639-1 A derived two lowercase code,<country/regioncode2> is a two-letter-uppercase code derived from ISO 3166. For example, American English is "en-us". In cases where the two-letter language code is not available, the three-letter code derived from ISO 639-2 is used; For example, the three-letter code "DIV" is used for areas using the Dhivehi language. Some culture names have the suffix of the specified writing symbol, for example, "-cyrl" specifies the Cyrillic notation, and "-latn" specifies the Latin writing symbol. Example:

Uzbek (Latin)-Uzbekistan TD style= "BORDER:0;PADDING:0;" >0x0009 "/tr>
culture name culture identifier language-country/region
zh-cn 0x0804 Chinese-China
ZH-TW Chinese-Taiwan
0x0004 Simplified Chinese
zh-cht 0X7C04 Traditional Chinese
en English
0x0409 English-United States
EN-GB 0x0809 English-UK
uz-uz-cyrl 0x0843 Uzbek (Cyrillic)-Uzbekistan
0x0443

The invariant culture is not culture-sensitive. You can use an empty string ("") to specify the invariant culture by name or by culture identifier 0x007f. The invariant culture represents an instance of the invariant culture by the InvariantCulture property of the CultureInfo class. The invariant culture is only associated with the English language and is not associated with any country/region. It can be used almost in all the methods in the "global" namespace that requires the culture. If your program is a string comparison or case change operation, you should use InvariantCulture to ensure that the behavior is done according to the invariant culture of the English language that InvariantCulture represents, regardless of how the system is set up. However, the invariant culture must be used only by processes (such as system services) that require results that are not dependent on the culture, or the results may be linguistically incorrect or culturally inappropriate. Example: CultureInfo INVC = New CultureInfo ("");

CultureInfo INVC = CultureInfo.InvariantCulture; The two lines of code function the same, in order to obtain a fixed culture instance.

For example, now you want to execute the DateTime.ToString () method on a DateTime instance DateTime. This method actually uses your CurrentCulture as the default culture, according to which the date instance is converted to the corresponding string form. So if we don't need it at this time to ToString by thread or system culture, then we should use this method DateTime.ToString ("G", CultureInfo.InvariantCulture) or DateTime.ToString ("G", Datetimeformatinfo.invariantinfo).

A neutral culture is a culture that is associated with a language but is not associated with a country/region. A specific culture is a culture that is associated with a language and a country/region. For example, "en" is a neutral culture, and "en-us" is a specific culture. Note that both "Zh-chs" and "Zh-cht" (traditional Chinese) are neutral cultures.

Cultures have hierarchies, that is, the parent of a specific culture is a neutral culture, and the parent of a neutral culture is invariantculture. The Parent property of the CultureInfo class returns the neutral culture associated with a specific culture. If the resources for a particular culture do not exist in the system or are unavailable for other reasons, use a resource that is not specific to the culture, or use the resources embedded in the main assembly if the resource for the neutral culture is not available.

3. Common types, attributes, and methods to achieve localization

The CultureInfo class represents information about a specific culture, including the name of the culture, the writing system, and the calendar used, as well as access to culture-specific objects that provide information about commonly used operations, such as formatting dates and sort strings. The instantiation of the CultureInfo class typically has two ways, as follows:

CultureInfo Culture = cultureinfo.createspecificculture (name);

CultureInfo Culture = new CultureInfo (name);

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