Web page multi-language Support solutions _ practical Tips

Source: Internet
Author: User

First set up 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 ' English
..............
=========================================
Then use the name--value key value pair to fill in the language you want to display on the page
Such as:
Name value
In Message.zh-cn.resx:
Res_loginbname Login Name:
In Message.zh-tw.resx:
Res_loginbname Name:
In Message.zh-cn.resx:
Res_loginbname Login Name:

=========================================
Then, add the multi-language setting support code in the Golbal.asax (the browser needs to support cookies)

'=========================================
' Application_BeginRequest Event
'
' The Application_BeginRequest method is a ASP.net event that executes
' On a Web request into the portal application.
'
' The thread culture is set to each request using the language
' Settings
'
'=========================================
Sub Application_BeginRequest (ByVal sender as Object, ByVal e as EventArgs)
Try
If not Request.Cookies ("resource") are 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 default language, which is called in Global.asax:

=========================================
<globalization requestencoding= "Utf-8" responseencoding= "Utf-8"/>
<appSettings>
<add key= "Defaultculture" value= "ZH-CN"/>
<!--ZH-CN: Simplified Chinese zh-tw: Chinese en: English-->
</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 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


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

To the multilingual support of the work done, then go to slowly key
Message.zh-cn.resx ' Simplified Chinese
Message.zh-tw.resx ' Traditional Chinese
Message.en ' English

These are some language files.

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.