【发布时间】:2011-04-28 09:55:25
【问题描述】:
在切换语言时,我正在努力从我的 \bin 文件夹中的资源文件中的正确 strings.txt 中获取值。
我有一个 domain.com(英语)和一个 domain.nl(荷兰语)。然而,我使用哪个域以及如何设置 currentUICulture 似乎并不重要,向用户显示的语言总是相同的!
[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")
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 文件夹中:
bin\strings.txt bin\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 中的值
我在带有 IIS7.5 的 Windows 7 上运行 当我调试时,我发现在我的 InitializeCulture 方法中:
Protected Overrides Sub InitializeCulture()
SetLanguage(Request.Url.ToString)
End Sub
当我检查当前的System.Threading.Thread.CurrentThread.CurrentUICulture.ToString 时,它等于“en”,所以似乎文化设置正确,只是没有使用正确的 strings.dll。
但是发生了更奇怪的事情:我在我的 default.aspx <asp:Literal ID="Literal1" runat="server" Text="<%$Resources:lookingfor%>" />中有这个
当我接近 www.domain.nl(荷兰域!)时,Literal1 控件显示来自“App_LocalResources\default.aspx.en.resx”的值,而 rm.getstring 显示来自 bin 的值\strings.txt 当我检查当前 System.Threading.Thread.CurrentThread.CurrentUICulture.ToString 它等于“nl”
当我接近 www.domain.com(英文域!)时,Literal1 控件显示来自“App_LocalResources\default.aspx.en.resx”的值,而 rm.getstring 显示来自 bin 的值\strings.txt 当我检查当前的
System.Threading.Thread.CurrentThread.CurrentUICulture.ToString时,它等于“en”
这是怎么回事?
所以在使用 www.domain.nl 时,使用了错误的 strings.dll,但使用了正确的 .resx
【问题讨论】:
标签: .net asp.net vb.net localization internationalization