国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計 > 正文

ASP.NET WEB頁面多語言支持解決方案

2019-11-18 19:33:35
字體:
供稿:網(wǎ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("項目文件名.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         '英文

這幾個語言檔吧,這是一個痛苦的回憶!


語言的后綴 如:
zh-cn'簡體中文
zh-tw'繁體中文
en   '英文

可以參考 IE選項---網(wǎng)際網(wǎng)絡(luò)設(shè)定--〉一般選項卡語言--〉新增里邊的內(nèi)容


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 金塔县| 灵山县| 灌云县| 大余县| 正阳县| 大埔县| 临西县| 叶城县| 庆城县| 靖西县| 清镇市| 屏山县| 建始县| 芦溪县| 丽水市| 闽侯县| 沁源县| 泸西县| 云霄县| 贵南县| 漠河县| 沙坪坝区| 安溪县| 苍溪县| 高碑店市| 武平县| 宝应县| 长垣县| 牟定县| 福安市| 阳信县| 霍邱县| 安义县| 毕节市| 嘉禾县| 郎溪县| 涞源县| 邵武市| 兰考县| 富蕴县| 黑河市|