First, create a language file and add the. resx file to the project.
For example:
Message. zh-cn.resx 'simplified Chinese
Message. zh-tw.resx 'traditional Chinese
Message. en'
..............
========================================================== =
Use Name -- Value Key-Value pairs to enter the language you want to display on the page.
For example:
Name value
Message. zh-cn.resx:
Res_loginbname:
Message. zh-tw.resx:
Res_loginbname:
Message. zh-cn.resx:
Res_loginbname Login Name:
========================================================== =
Then add the multi-language setting support code to Golbal. asax (the browser needs to support cookies)
'================================================ =
'Application_beginrequest Event
'
'The Application_BeginRequest method is an ASP. NET event that executes
'On each web request into the portal application.
'
'The thread culture is set for each request using The language
'Settings
'
'================================================ =
Sub Application_BeginRequest (ByVal sender As Object, ByVal e As EventArgs)
Try
If Not Request. Cookies ("resource") Is Nothing Or Request. Cookies ("resource"). Value = "" Then
Thread. CurrentThread. CurrentCulture = CultureInfo. CreateSpecificCulture (Request. Cookies ("resource"). Value)
Else
Thread. CurrentThread. CurrentCulture = New CultureInfo (ConfigurationSettings. deleetture ("DefaultCulture "))
End If
Thread. CurrentThread. CurrentUICulture = Thread. CurrentThread. CurrentCulture
Catch ex As Exception
Thread. CurrentThread. CurrentCulture = New CultureInfo (ConfigurationSettings. deleetture ("DefaultCulture "))
End Try
End Sub 'application _ BeginRequest
Add the following code to Web. Config to set the encoding and default language, which is called in Global. asax:
========================================================== =
<Globalization requestEncoding = "UTF-8" responseEncoding = "UTF-8"/>
<Deleetask>
<Add key = "DefaultCulture" value = "zh-cn"/>
<! -- Zh-cn: Simplified Chinese zh-tw: Traditional Chinese en: English -->
</AppSettings>
========================================================== =
Multiple languages are supported in the page code:
Imports System. Resources
Public Class name
Inherits System. Web. UI. Page
Protected LocRM As ResourceManager = New ResourceManager ("project file name. message", GetType (Class Name). Assembly)
Private Sub Page_Load (ByVal sender As System. Object, ByVal e As System. EventArgs) Handles MyBase. Load
LblLogin. Text = LocRM. GetString ("res_login ")
End Sub
End Class
========================================================== =
Now the multi-language support work is complete, and then slowly go to the Key
Message. zh-cn.resx 'simplified Chinese
Message. zh-tw.resx 'traditional Chinese
Message. en'
These languages