ASP. NET Website implementation multi-language version

Source: Internet
Author: User
I. Project Overview

1. Purpose
Resource files are used to solve the problem of multilingual website versions. When creating a website, you often encounter versions in multiple languages. In the early stage of ASP, many website developers use the traditional method to develop the same set Program Copying two copies is implemented, but maintenance in the later stage often brings a lot of trouble. In the Asp.net era, it was so simple to do this.
2. Concepts
A resource file is an XML file that contains strings to be converted to different languages or image paths. The resource file contains key/value pairs, each of which is a separate resource. The key name is case insensitive. For example, a resource file may contain resources with the button1 key and the submit value.
Multiple languages are used to create a resource file for each language (such as English and French) or for each language and region (such as English [UK] and English [us. Each localized resource file has the same key/value pair. The only difference between a localized resource file and a default resource file is that the former may contain fewer resources than the latter. Then, the language rollback process loads non-specific or default resources.
The resource file in ASP. NET has the. resx extension. At runtime, The. resx file will be compiled into an assembly, which is sometimes called a ancillary assembly. Because the. resx file is dynamically compiled in the same way as the ASP. NET webpage, you do not need to create a resource assembly. The compilation process compresses resource files similar to multiple languages in the same assembly.
When creating a resource file, first create the base file. resx. Create a new file for each language that you want to support. The file has the same basic file name but contains the language, language, and Culture (Regional name ). For a list of regional names, see cultureinfo. For example, you can create the following files:

Webresources. resx

Base Resource file. This file is a default or backup resource file.

Webresources. es. resx

Spanish resource file.

Webresources. es-mx.resx

Resource files dedicated to Spanish (Mexico.

Webresources.de. resx

German resource file.

At runtime, ASP. NET uses the resource file that best matches the settings of the currentuiculture attribute. The UI culture of the thread is set based on the UI culture of the page. For example, if the current UI culture is Spanish, ASP. NET uses the compiled version of The webresources. es. resx file. If no match exists for the current UI culture, ASP. NET will use resource backup. First, use resources of a specific culture, then use a non-specific culture, and finally use the default resource file. In this example, the default resource file is webresource. resx.

Ii. Solutions

1. Global Resource file (app_globalresources)
Place the resource file in the app_globalresources folder of the application root directory to create a global resource file. Any. resx file in the app_globalresources folder has a global range. In addition, ASP. NET also generates a strongly typed object, which provides developers with a simple way to access global resources programmatically.

2. Local resource file (app_localresources)
A local resource file is a file that only applies to one ASP. NET page (an ASP. NET page with extensions such as. aspx,. ascx, And. Master ). The folder to which the local resource file is placed has a reserved name of app_localresources. The app_localresources folder can exist in any folder of the application, which is different from the app_globalresources root folder. Associate a group of resource files with a specific webpage by using the resource file name.

For example, if there is a page named default. aspx in the app_localresources folder, you can create the following files:

Default. aspx. resx

Default local resource file. If no language match is found, the file is a backup resource file.

Default. aspx. es. resx

A Spanish resource file that does not contain regional information.

Default. aspx. es-mx.resx

Resource files dedicated to Spanish (Mexico.

Default. aspx. Fr. resx

A French resource file that does not contain regional information.

3. Use the implicit localization of local resources
In the Server Control Reference example:Meta: resourcekey = "button1"/>
In the corresponding resource file definition: button1.text

4. Explicit Localization
Page reference as shown inTEXT = ""/>
Resource file definition: button1caption

When a page is running and ASP. net is retrieving values from the Resource Manager, Asp.. Net selects the resource file version with the highest degree of matching with the current uiculture for this page, or uses resource backup to obtain resources. For example, if you are running default. ASP. net uses the local resource file default. aspx. es. the compiled version of resx.

ASP. NET can set the uiculture and culture attributes of the page to the language and culture values passed by the browser. Alternatively, it can be declared or usedCodeExplicitly set the uiculture and culture attributes. You can also set these values in declaration in the web. config file. For more information, see How to: Set a culture and UI culture for ASP. NET web page globalization.
To be webpage content from Microsoft official website, I have done sorting, address (http://msdn2.microsoft.com/zh-cn/library/ms227427 (vs.80). aspx)

I upload an instance, hoping to help you. Link

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.