Implementation and consideration of asp.net supporting multilingual sites

Source: Internet
Author: User

First, let's take a look at the file structure in my solution Resource Manager:

Here, the App_GlobalResources file is critical. It is a type of resource file used by ASP. NET to create a website.

It is necessary to first introduce ASP. NET Website Resource files:

"In ASP. NET, you can create resource files with different scopes. You can create global resource files, which means you can read these resource files from any page or code on the website. You can also create local resource files that store the resources of a single ASP. NET webpage (. aspx file ."

Global Resource file

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 generates a strongly typed object, providing a simple way to access global resources programmatically.

Local resource file

A local resource file is a file that only applies to one ASP. NET page or user control (an ASP. NET file with the extension. aspx,. ascx, or. master ). The folder to which the local resource file is placed has a reserved name of App_LocalResources. Unlike the root App_GlobalResources folder, The App_LocalResources folder can be located in any folder of the application. You can 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. This is the default local resource file when no language match is found (the resource file is rolled back ).

  • Default. aspx. es. resx. This is a Spanish resource file that does not contain regional information.

  • Default. aspx. es-mx.resx. This is a resource file dedicated to Spanish (Mexico.

  • Default. aspx. fr. resx. This is a French resource file that does not contain regional information.

The base name of the file is the same as the page file name, followed by the Language and Culture name, and ended with the extension. resx. For a list of regional names, see CultureInfo.

CultureInfo

For details, see MSDN: ms-help: // MS. MSDNQTR. v90.chs/fxref_mscorlib/html/63c619e3-0969-2f01-a2d4-79d0868a98c6.htm.

That is to say, the names of the two parts marked with red lines in the graph cannot be obtained by yourself. You must refer to the CultureInfo table to name them.

File Information in WebResources. en. resx:

File Information in WebResources. resx:

Source Design Code of Default. aspx:

<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> Implementation of asp.net support for multilingual sites </title>
</Head>
<Body>
<Form id = "form1" runat = "server">
<Div>
<Asp: Calendar ID = "Calendar1" runat = "server"> </asp: Calendar>
<Asp: Button ID = "Button1" runat = "server" OnClick = "button#click" Text = "OK"/>
<Asp: Label ID = "Label1" runat = "server" Text = "Label"> </asp: Label>
</Div>
</Form>
</Body>
</Html>

Code for Default. aspx. cs:

Using System;
Using System. Collections;
Using System. Configuration;
Using System. Data;
Using System. Linq;
Using System. Web;
Using System. Web. Security;
Using System. Web. UI;
Using System. Web. UI. HtmlControls;
Using System. Web. UI. WebControls;
Using System. Web. UI. WebControls. WebParts;
Using System. Xml. Linq;

Namespace OneSiteMultiLanguage
{
Public partial class _ Default: System. Web. UI. Page
{
Protected void Page_Load (object sender, EventArgs e)
{
Page. Title = Resources. WebResources. pagefile;
Response. Write (Resources. WebResources. Question + "<br/> ");
}

Protected void button#click (object sender, EventArgs e)
{
Int days = DateTime. Now. DayOfYear-Calendar1.SelectedDate. DayOfYear;
If (days> 0)
{
Label1.Text = string. Format (Resources. WebResources. Answer, (365-days). ToString ());
}
Else
{
Label1.Text = string. Format (Resources. WebResources. Answer, Math. Abs (days). ToString ());
}
Button1.Text = string. Format (Resources. WebResources. buttondomaintext );
}
}
}

The running result is as follows:

Pay attention to the attribute values in the culture in the Default. aspx file.

In addition, to allow the browser to display webpage content in Chinese, you can set "tool"> "interner option"> "language" in the browser.

 Set to Chinese and then run the display:

------ End ------

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.