WEB page multi-language support Solution

Source: Internet
Author: User

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

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.