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利用NamingContainer屬性獲取GridView行號的方法
在最近的一個(gè)項(xiàng)目中,用到在GridView模板列中添加有DropDownList控件,并開啟其AutoPostback屬性。當(dāng)發(fā)生SelectedIndexChanged事件時(shí),想同時(shí)獲取其所在的行號,從而獲取相應(yīng)的行信息。2013-07-07
Asp.net 通用萬級數(shù)據(jù)分頁代碼[修正下載地址]
在萬級數(shù)據(jù)量下的分頁代碼2008-10-10
the sourcesafe database has been locked by the administrator
今天早上打開soucesafe的時(shí)候出現(xiàn)提示:“the sourcesafe database has been locked by the administrator"。仔細(xì)想想, 可能是前天晚上用"f:\analyze.exe" -I- -DB -F -V3 -D "f:\vssData\data" 命今分析的時(shí)候鎖定了database2009-04-04
ASP.net Substitution 頁面緩存而部分不緩存的實(shí)現(xiàn)方法
在ASP.NET中要實(shí)現(xiàn)部分內(nèi)容非緩存,而其它的都需要緩存輸出,可以使用Substitution控件實(shí)現(xiàn).2009-03-03
.NetCore?Web?Api?利用ActionFilterAttribute統(tǒng)一接口返回值格式及問題解析
在實(shí)際項(xiàng)目開發(fā)過程中,統(tǒng)一API返回值格式對前端或第三方調(diào)用將是非常必要的,在.NetCore中我們可以通過ActionFilterAttribute來進(jìn)行統(tǒng)一返回值的封裝,對.NetCore?Web?Api?統(tǒng)一接口返回值格式相關(guān)知識感興趣的朋友一起看看吧2022-03-03
Ajax Throws Sys.WebForms.PageRequestManagerErrorException wi
注冊腳本: ScriptManager.RegisterStartupScript(this, typeof(string), "Message", "alert('error message');", true); 即可解決,困惑了我一下午。2008-11-11
分享Visual Studio原生開發(fā)的10個(gè)調(diào)試技巧
我整理了一些Visual Studio 至少在VS 2008下 原生開發(fā)的調(diào)試技巧,下面是我的整理的一些技巧,需要的朋友可以參考下2013-08-08

