[Repost] ASP.NET Web Page Multilingual Support Solutions

xiaoxiao2021-03-06  17

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

====================================================== The key value is filled in the language you want to display on the page such as: RES_LOGINBNAME Land Name: message.zh-tw.resx: RES_LOGINBNAME Land Name: Message.zh-cn.resx Medium: res_loginbname login name:

======================================================= in Golbal.asax Add multilingual setting support code (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.' '' 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 = threeread.currentthread.currentculture catch exception thread.currentthread.currentcultu, tits ,s.cURRENTUTULTULTULTULTULTULTURENTTHREAD.CURRENTCULTUTULTULTULTULTURENTTHREAD. Re = New CultureInfo ("DefaultCulttings.AppSettings)) End Try End Sub 'Application_BeginRequest Add to the following code to set the encoding and default language, there is called in Global.asax:

========================================================= ======================================= ========== Use multi-language 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-41918.html

New Post(0)