.NET globalization should pay attention to

xiaoxiao2021-03-06  26

1. Use the resource to store all interface text:

This should be the largest workload, the most cumbersome, and the most basic part. All text involved in the page (including the text on the label, error message, etc.) should be written to the resource file; then, the page load , Write text from the resources to those Label.

We can use the placeholders such as {0} {1} instead of some places that need to be inserted into the variable, use the String.Format method to populate these placeholdings. (Of course, the placeholder can have format information, such as the date type, {0: g}, etc.) If you use a placeholder, please note that if the resource cannot be found, or find it It is an empty string, then it will be wrong when String.Format. So please be sure to ensure that the resource item exists.

2. Naming of resource files

In accordance with certain rules, if the root-level non-fixed regional resource file is named: strings.resx, the resource file name of EN-CHS should be: strings.zh-chs.resx; class push, ZH-CN resource files should be Strings.zh-cn.resx.

3. Fixed regionality and non-fixed regionality

Fixed regional code, such as: zh-CN (Chinese-People's Republic of China), EN-US (English - USA), JA-JP (Japanese - Japan). Non-fixed regionality, such as: zh-CHS (Simplified Chinese), EN-CHT (Traditional Chinese), En (English), JA (Japanese). When the system finds resources, if the resource is found for the ZH-CN, it will first look for whether the resources of the ZH-CN exists; if not found, it will automatically find its "parent" non-fixed area, ie zh-chs resources. If it is still not found, INVARIANTCULTURE (root-level non-fixed regional resources) is used.

Because of EN-CN, EN-SG, EN-MO these fixed areas are used in EN-CHS Simplified Chinese, most text should be the same; if EN-CHS is used to make Simplified Chinese resources, its child's ZH-CN EN-SG, EN-MO will use this Simplified Chinese resource; individual inconsistent resources, can be single column in various sub-regional resource files.

According to the above features: (a.) A non-fixed regional resource such as EN-CHS, EN, JA is preferred. (b) If EN-CN and EN-SG or EN-Mo are different in certain resource items, you can use a single column. This makes it easy to compatibility with more regional.

4. Different fixed regions have different datetime digital display formats:

Simply, the most used is the display format of the DateTime, and the visitor should provide the visitor in different regions. For example, we usually like the DateTime.Tostring ("YYYY-MD") method, which is the same in different regional output results. Do not meet our purpose, you should use DateTime.toString ("D"), DateTime. TOSTRING ("f") is used in different formats in different regions. (, Such as "D": EN-CN: 2004-9-11; JA-JP: 2004/09/11; EN-US: 9/11/2004) Need to note that these must be associated with fixed area Combined. Non-fixed regional is not talking about this format, such as the use of English-speaking US and UK, its format is also different.

5. Place your language on the page Select DropDownList:

Setting its AutoPostBack property to true; Value attributes for the ListItem in three languages ​​are: EN-US, EN-CN, JA-JP.

In the language selection of DropDownList, we need to change the regionality of the current session. The simple way is: two only write properties (WRITE-ONLY): String Culture and String Uicle: String Culture and String Uicle (these two are only written, can not be read, "in the" .NET Category Database " they). Culture needs to be configured with a fixed area, and UICURE accepts a non-fixed regional code in addition to the fixed area code. In general, we can assign a value, such as: culture = "zh-cn", uiculture = "zh-chs" (of course, it can also be written directly "zh-cn").

6. About text Sort:

Different languages ​​may be different from the same characters, such as: Swedish and German have letters "Ä", but Swedish is after Z, and German is after A. This situation in Western languages, there are not many contacts.

This time, it is Simplified Chinese, English, Japanese three language. For example, Chinese and Japanese have Chinese characters, but Simplified Chinese is sorted by Chinese Pinyin, "Xue" after "Sheng"; Japanese is sorted by false name, "Learn" (がく) " Before (せ せ).

The text sorting, in the .NET program is associated with the area code, specific to the ASP.NET site, after the previous article assigns "zh-cn" for Page.culture, if "learning" and "students" If you are compared, you will be compared according to the language already specified.

But this is within the program, the actual situation is often: For example, when the page is displayed on 10,000 pieces of data, we are in the order in the database, only one page (20 or 40 or PageSize strips), return to Program handling; if we are just sorting these 20 or 40 data in the program, this is just the 20 or 40 records of the already removed, of course, not what we want.

That is to say, this sorting rule needs to be specified in the database end, in the Oracle database's PL / SQL language, we found the ALTER Session Set NLS_SORT = SCHINESE_PINYIN_M;

Write this sentence to the stored procedure / function of query data, the ordering operation in this stored procedure / function (ORDER BY ...) will be sorted by Chinese Pinyin; Japanese is

Alter session set nls_sort = japanese;

Other languages, we can use the default

Alter session set nls_sort = binary;

Passing a number representing different regions, and the SQL on the stored procedure can be used to achieve the desired purpose.

Here is wrong! Alter session can not be used during storage, you can only use the NLS_SORT function! Special amendment:

Select ..... from .... where ..... Order by NLS_SORT (Sort Field Name, 'NLS_SORT = SCHINESE_PINYIN_M') DESC;

Unfortunately, I didn't find a similar operation in the T-SQL language of SQL Server (which one knows can tell me), according to my currently known: SQL Server only supports "static" sort rules, you can give one The field of Char, VARCHAR, TEXT, NVARCHAR, NTEXT specifies the sorting rules, but the specified can not change this rule during the stored procedure, that is, a field can only be sorted by a rule, and cannot be dynamically changed. It seems that SQL Server is temporarily unable to meet our needs.

The situation in other databases, not knowing, knowing friends, please stay below, share them together.

7. Display format issues in internal processing

For example, we pass a date parameter to another via query string, then we should use and regionally independent fixed format, such as DateTime.toString ("YYYYMMDD"), so where is We have got a string of 20040911, which is convenient for "reception" on the other side.

That is, internal processing needs to use and regionically unrelated fixed formats when passing text; and display and regional related formats are displayed.

转载请注明原文地址:https://www.9cbs.com/read-40895.html

New Post(0)