asp.net从\ bin文件夹文件中的文件本地化文本

时间:2011-04-01 18:36:29

标签: vb.net resources localization globalization

在切换语言时,我很难从我的\ bin文件夹中的资源文件中获取正确strings.txt中的值。

[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
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中的值被使用而NOT(就像我期望和期望的那样),来自bin \ en \ strings.en.txt的值< / p>

为什么?

1 个答案:

答案 0 :(得分:0)

我在.NET 4.0 Windows 2008计算机上尝试了您的代码段。它就像你想要它一样有效。

我唯一能想到的......我试过的电脑安装了Windows MUI。想知道这是否是一个因素?