在切換語言時,我在\ bin文件夾中的資源文件中從正確的strings.txt中獲取值,並付出了努力。asp.net從 bin文件夾文件中的文件本地化文本
[default.aspx.vb]
Partial Class _Default
Inherits System.Web.UI.Page
Shared rm As ResourceManager = HttpContext.Current.Application("RM")
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Label.Text = rm.GetString("homewelcome") '"Alles over trouwen, voor je perfecte bruiloft"
End Sub
Protected Overrides Sub InitializeCulture()
SetLanguage(Request.Url.ToString)
End Sub
Public Shared Sub SetLanguage(ByVal URL As String)
Dim lang As String = ""
If URL.Contains("www.domain.nl") Then
lang = "nl"
ElseIf URL.Contains("www.domain.com") Then
lang = "en"
End If
System.Threading.Thread.CurrentThread.CurrentUICulture = New System.Globalization.CultureInfo(lang)
System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture(lang)
End Sub
End Class
[Global.asax中]
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
Application("RM") = New ResourceManager("strings", Assembly.Load("strings"))
End Sub
在我的bin文件夾我有:
斌\ strings.txt
斌\ nl \ strings.nl.txt
bin \ en \ strings.en.txt
我產生像這樣的dll文件:
resgen strings.txt strings.resources
al /embed:strings.resources,strings.resources /out:strings.dll
resgen nl\strings.nl.resources
al /embed:nl\strings.nl.resources,strings.nl.resources /out:nl\strings.resources.dll /c:nl
resgen en\strings.en.resources
al /embed:en\strings.en.resources,strings.en.resources /out:en\strings.resources.dll /c:en
現在,所有的文件似乎正確創建。
但是,當我訪問www.domain.com時,bin \ strings.txt中的值被使用,而不是(像我期望和渴望的那樣),bin \ en \ strings.en.txt中的值
爲什麼?
好奇... www.domain.nl是否有效? – Naraen 2011-04-01 21:27:49