. NET resource file globalization

Source: Internet
Author: User

I: This blog post code example

I haven't been writing essays for a long time.

Then directly on [code]

II:ASP.NET Resource File Introduction

In the ASP. NET special folder There are two less noticeable, they are app_globalresources, app_localresources.

Resource file naming convention: {File name}. {Zone}.resx
{Region} This one is negligible. When you omit the {region}, if the Page.uiculture and the {zone} provided in the resource file do not have a number, it will be rendered with a resource file that does not have the {zone} set.

For example, when page.uiculture = "JA-JP", and the resource file is only
Resource.resx
Resource.zh-cn.resx
Resource.zh.resx
Resource.en.resx
Resource.en-us.resx
Asp. NET is rendered using the default Resource.resx because the Resource.ja-jp.resx is not found.




Asp. NET Resource folder

App_GlobalResources: The set of resource files that can be called to the entire station (e.g. a.aspx,b.aspx,c.aspx can be shared)

App_LocalResources: A set of resource files that can be called only by a single page, such as a.aspx only mapped to a.aspx.{ Zone}.resx, b.aspx maps to b.aspx. {Zone}.resx)

Each resource file represents a resource file that is required for a regional language. Example Myglobalresources

Here first introduce the sub-node in Web. config <system.web> under <globalization/>

Here I set the UICulture to "auto". The properties of the page.uiculture will automatically correspond to the locale set for the client browser:

The settings in the reqeust will affect the accept-language information of the browser-initiated header, which corresponds to the following:

If the UICulture is not set to "Auto", ASP. NET system will not automatically map the language environment of the client browser to Page.uiculture.

In the second file structure about. resx I won't explain. I'm sure you're familiar with it. It is similar to Key/value configuration.

Iii. Use of resource files in ASP.

In the project code provided above. I only wrote 3 languages (Chinese, English, Korean) resources. Its configuration into:

Here is a description of how to use the ASPX page.


<%$ resources:{class name}, {Resource file node}%> call only App_GlobalResources resource file


<%$ resources:{Resource file node}%> call only app_localresources resource file


Note: Such tokens must be used in the runat= "Server" tab of the properties using the example:

<asp:literal id= "Ltlsitename" runat= "Server" text= "<%$ resources:myglobalresources, SiteName%>" ></ Asp:literal>

<asp:literal id= "Ltlpassword" runat= "Server" text= "<%$ resources:password%>" >

Alternatively, you can use the meta:resourcekey= "ID" method:

Also code generation for resource files. Can be configured by:

What else can you see in the example code first!

The code in this article allows the customer to select a locale and then put it into a cookie, and then the landing page will invoke the resource file rendering interface according to the user's chosen locale.

Here I believe you also understand the shortcomings: a page of 3 languages, you need to configure 3. resx files! I think it's a bit of a convenience!



This article concludes. Thank you!

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.