WEB頁面多語言支持解決方案
首先建立語言檔,在項(xiàng)目中加入.resx文件
例如:
message.zh-cn.resx '簡體中文
message.zh-tw.resx '繁體中文
message.en '英文
..............
=========================================
然后利用Name --Value 鍵值對 填入你要在頁面上顯示的語言
如:
name value
message.zh-cn.resx中:
res_loginbname 登陸名 :
message.zh-tw.resx中:
res_loginbname 登陸名 :
message.zh-cn.resx中:
res_loginbname Login Name :
=========================================
然后在Golbal.asax中加入多語言設(shè)定支持代碼(瀏覽器需要支持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
在Web.Config中加入如下代碼,用于設(shè)定編碼和默認(rèn)語種,在Global.asax中有調(diào)用:
=========================================
<globalization requestEncoding="utf-8" responseEncoding="utf-8" />
<appSettings>
<add key="DefaultCulture" value="zh-cn" />
<!-- zh-cn:簡體中文 zh-tw:繁體中文 en:英文 -->
</appSettings>
=========================================
頁面代碼中使用多語言支持:
Imports System.Resources
Public Class 類名
Inherits System.Web.UI.Page
Protected LocRM As ResourceManager = New ResourceManager("項(xiàng)目文件名.message", GetType(類名).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
=========================================
到這里多語言支持的工作就作完了,接下來自己去慢慢Key
message.zh-cn.resx '簡體中文
message.zh-tw.resx '繁體中文
message.en '英文
這幾個(gè)語言檔吧
相關(guān)文章
對ASP.Net的WebAPI項(xiàng)目進(jìn)行測試
這篇文章介紹了對WebAPI項(xiàng)目進(jìn)行測試的方法,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-04-04asp.net中c#自定義事件的實(shí)現(xiàn)方法詳解
這篇文章主要介紹了asp.net中c#自定義事件的實(shí)現(xiàn)方法,較為詳細(xì)的分析了自定義實(shí)現(xiàn)的各個(gè)步驟的具體實(shí)現(xiàn)思路與技巧,并給出了一個(gè)完整的實(shí)例總結(jié),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2014-12-12asp.net 自定義控件實(shí)現(xiàn)無刷新上傳圖片,立即顯示縮略圖,保存圖片縮略圖
自定義控件實(shí)現(xiàn)無刷新上傳圖片,立即顯示縮略圖,保存圖片縮略圖2010-01-01asp.net?core實(shí)體類生產(chǎn)CRUD后臺(tái)管理界面
這篇文章主要為大家介紹了asp.net?core實(shí)體類生產(chǎn)CRUD后臺(tái)管理界面詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-05-05Asp.net利用JQuery彈出層加載數(shù)據(jù)代碼
最近看QQ空間里面的投票功能很使用。點(diǎn)擊一個(gè)鏈接就彈出一個(gè)層,然后再加載一些投票信息,旁邊的區(qū)域變成灰色不可用狀態(tài)。其實(shí)這不算什么高深的技術(shù),只要在ASP.NET中利用JQuery結(jié)合一般處理程序ASHX即可搞定了。2009-11-11DropDownList綁定數(shù)據(jù)表實(shí)現(xiàn)兩級聯(lián)動(dòng)示例
這篇文章主要介紹了DropDownList綁定數(shù)據(jù)表實(shí)現(xiàn)兩級聯(lián)動(dòng)具體實(shí)現(xiàn),需要的朋友可以參考下2014-03-03WPF集合控件實(shí)現(xiàn)分隔符(ItemsControl Separator)
這篇文章主要為大家詳細(xì)介紹了WPF集合控件實(shí)現(xiàn)分隔符ItemsControl Separator,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-04-04ASP.NET Web Api 2實(shí)現(xiàn)多文件打包并下載文件的實(shí)例
這篇文章主要介紹了ASP.NET Web Api 2利用ByteArrayContent和StreamContent實(shí)現(xiàn)多文件打包并下載的方法,提供源碼下載,需要的朋友可以參考下。2016-06-06