ASP.NET Web Page Multilingual Support Solutions

xiaoxiao2021-03-06  39

First establish a language file, join .e.resx file, for example: message.zh-cn.resx 'simplified Chinese message.zh-tw.resx' 体 ​​中文 Message.en 'English ......... ...

============================================================================================================================================================================================================= ==================== Then use the name -value key value to fill in the language you want to display on the page such as: name value message.zh-cn.resx Medium: RES_LOGINBNAME Land Name: Message.zh-Tw.RESX: RES_LOGINBNAME Land Name: Message.zh-cn.resx: Res_loginbname Login Name:

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

'==================================================== ==================================================== 'Application_BeginRequest Event' ' 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 E AS Object, BYVAL E AS Eventargs) TRY 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 In Web.Config Add the following code to set the encoding and default language, there is called in global.asax:

============================================================================================================================================================================================================= ===================== 简体 中文 EN: 体 中文 EN: English->

============================================================================================================================================================================================================= ==================== Using multilingual support in page code:

Imports system.resources

Public Class Your Class Inherits System.Web.ui.page Protected LoCRM As ResourceManager = New ResourceManager ("Project File Name .Message", gettype (class name) .assembly

Private sub page_load (Byval E AS System.EventArgs) Handles mybase.load lbllogin.text = LoCRM.GETSTRING ("res_login") End Subend class ============== ============================================================================================================================================================================================================= =======

It's finished with the work of multilingual support here, next to yourself KeyMessage.zh-cn.resx 'Simplified Chinese Message.zh-Tw.resx' Traditional Chinese Message.en 'in English

These languages, this is a painful memory!

The suffix of language such as: zh-cn 'simplified Chinese en-TW' Traditional Chinese EN 'English

Can refer to IE Options - Network Settings -> General Tab Language -> Content

转载请注明原文地址:https://www.9cbs.com/read-118463.html

New Post(0)