2011-04-01 51 views
0

在切換語言時,我在\ 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中的值

爲什麼?

+0

好奇... www.domain.nl是否有效? – Naraen 2011-04-01 21:27:49

回答

0

我在.NET 4.0 Windows 2008計算機上試過了您的代碼片段。它按照你想要的那樣工作。

我能想到的唯一一件事......我試過的電腦上安裝了Windows MUI。想知道這是否是一個因素?

+0

我在Windows 7上運行,只有英文,所以我希望這部分工作至少。我調試了一下,發現在畝InitializeCulture方法:保護覆蓋Sub InitializeCulture() SetLanguage(Request.Url.ToString) End Sub 當我檢查當前的System.Threading.Thread.CurrentThread.CurrentUICulture.ToString它的等於「en」,所以看起來文化是正確設置的,只有不正確的strings.dll被使用....這有助於進一步幫助我嗎? :) – Peter 2011-04-03 14:13:49

+0

但還有更奇怪的事情發生: 此外,我有這在我的default.aspx 」/ > 當我接近www.domain.com時,Literal1控件顯示來自「App_LocalResources \ default.aspx.en.resx」的值 而當我檢查當前的System.Threading.Thread.CurrentThread.CurrentUICulture.ToString時等於「en」,所以看起來文化是正確設置的。 所以當使用www.domain.com時,使用了WRONG strings.dll,但是正確的.resx文件......對我來說似乎有點不一致! – Peter 2011-04-03 21:20:40

相關問題