在切换语言时,我在\ 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