Asp.net 2.0 multilingual website development solution

Source: Internet
Author: User
App_globalresources in Asp.net 2.0 can be used to solve the localization problem. The program automatically determines the localized Interface Based on the browser's language preferences.

Create a resx resource file in app_globalresources. For example:

In resx of different languages, the project should have the same name:

Chinese Resource item

English resource items

These names can be used right after they are finished,

<Asp: literal id = "literal1" runat = "server" text = "<% $ resources: Lang, userinfo %>"/>

Or

<% = Resources. Lang. userinfo %>

Now you can change the browser's language preference to see the effect.

The next question is how to replace the language item through the program itself.

1. You can add <globalization culture = "En-us" uiculture = "En-us"/> to Web. config to change the default language used by the program.

2. Add the following code to the global application:

Void application_beginrequest (Object sender, eventargs E)

{

Try

{

If (request. Cookies ["Lang"]! = NULL)

{

System. Threading. thread. currentthread. currentculture = system. Globalization. cultureinfo. createspecificculture (request. Cookies ["Lang"]. value. tostring ());

System. Threading. thread. currentthread. currentuiculture = new system. Globalization. cultureinfo (request. Cookies ["Lang"]. value. tostring ());

}

}

Catch (exception)

{}

}

You can change the cookie value to achieve real-time language switching, and easily implement multiple programming languages.

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.