First, create a new resx resource file in App_GlobalResources. Such as:
Items in ResX in different languages should have the same name:
Chinese resource items
English resource items
After that, you can use these name values.
Copy Code code as follows:
<asp:literal id= "Literal1" runat= "Server" text= "<%$ resources:lang,userinfo%>"/>
Or
Copy Code code as follows:
<%=Resources.lang.userinfo%>
Now you can change the browser's language preferences to see the effect.
The next question is how to replace the language items by the way the program itself is.
1. You can add <globalization culture= "en-us" uiculture= to Web.config to change the language items that the program uses by default.
2. You can add the following code to global application
Copy Code code as follows:
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 cookie value to achieve the goal of instant switching language, easy to implement the program's multi-language.
Download Test: Global.rar (8.36 KB)