WEB page multi language support solution

  • 2020-05-05 11:09:16
  • OfStack

First, create the 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 '
..............
=========================================
Then use the Name --Value key-value pair to fill in the language
that you want to display on the page Such as:
name value
message. zh - cn. resx:
res_loginbname login name :
message. zh - tw. resx:
res_loginbname :
message. zh - cn. resx:
res_loginbname Login Name :

=========================================
Then add the multilingual support code in Golbal.asax (the browser needs to support Cookie)

'=========================================
' 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.AppSettings("DefaultCulture"))
End If
Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture
Catch ex As Exception
Thread.CurrentThread.CurrentCulture = New CultureInfo(ConfigurationSettings.AppSettings("DefaultCulture"))
End Try
End Sub 'Application_BeginRequest

Add the following code in Web.Config to set the encoding and the default language, which is called in Global.asax:

=========================================
< globalization requestEncoding="utf-8" responseEncoding="utf-8" / >
< appSettings >
< add key="DefaultCulture" value="zh-cn" / >
< ! -- zh -- cn -- zh -- tw -- en -->
< /appSettings >

 

=========================================
Multi-language support in page code:

Imports System.Resources

Public Class class name
Inherits System.Web.UI.Page
Protected LocRM As ResourceManager = New ResourceManager(" project filename.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


=========================================

The work of multilingual support is done here, then go slowly on your own Key
message.zh-cn.resx 'simplified Chinese
message.zh-tw.resx 'traditional Chinese
message.en '

These language files are


Related articles: