. NET Multi-lingual support solutions (RPM)

Source: Internet
Author: User

App_GlobalResources in ASP. NET 2.0 can be used to solve localization problems, and the program will automatically determine the localized interface based on the browser's language preferences.

First create a new RESX resource file in App_GlobalResources. Such as:

Items in the ResX in different languages should have the same name:

Chinese resource Item

English resource items

When you're done, you can use these name values.

<asp:literal id= "Literal1" runat= "Server" text= "<%$ resources:lang,userinfo%>"/>

Or

<%=Resources.lang.userinfo%>

Now you can change your browser's language preferences to see the results.

The next question is how to change the language item by the way the program itself.

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

2. You can 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)
{ }
}

Can be set to change the value of the cookie to achieve the purpose of instant switching language, easy to implement the program's multi-language.

. NET Multi-lingual support solutions (RPM)

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.