Im struggling with gettings the values from the correct strings.txt in my resource files in my in folder when switching languages.
I have a domain.com (for English) and a domain.nl (for Dutch). It however doesnt seem to matter which domain I use and how I set the currentUICulture, the language shown to the user is always the same!
[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
In my bin folder I have:
binstrings.txt bin lstrings.nl.txt binenstrings.en.txt
I generate the dlls like so:
resgen strings.txt strings.resources
al /embed:strings.resources,strings.resources /out:strings.dll
resgen nlstrings.nl.resources
al /embed:nlstrings.nl.resources,strings.nl.resources /out:nlstrings.resources.dll /c:nl
resgen enstrings.en.resources
al /embed:enstrings.en.resources,strings.en.resources /out:enstrings.resources.dll /c:en
Now, all files seem to be created correctly.
However, when I go to the www.domain.com, the values from binstrings.txt are used and NOT (like I would expect and desire), the values from binenstrings.en.txt
Im running on Windows 7 with IIS7.5 When I debugged I found that in my InitializeCulture method:
Protected Overrides Sub InitializeCulture()
SetLanguage(Request.Url.ToString)
End Sub
when I check for the current System.Threading.Thread.CurrentThread.CurrentUICulture.ToString
its equal to "en", so it seems that the culture is SET correctly, its only that not the correct strings.dll is used.
But there's a more strange things going on: I have this in my default.aspx <asp:Literal ID="Literal1" runat="server" Text="<%$Resources:lookingfor%>" />
When I aproach www.domain.nl (the Dutch domain!), the Literal1 controls displays the value from "App_LocalResourcesdefault.aspx.en.resx" and the rm.getstring shows me a value from binstrings.txt And when I check the current System.Threading.Thread.CurrentThread.CurrentUICulture.ToString its equal to "nl"
When I aproach www.domain.com (the English domain!), the Literal1 controls displays the value from "App_LocalResourcesdefault.aspx.en.resx" and the rm.getstring shows me a value from binstrings.txt And when I check the current
System.Threading.Thread.CurrentThread.CurrentUICulture.ToString
its equal to "en"
What is going on here?
So when using www.domain.nl, the WRONG strings.dll is used, but the CORRECT .resx
See Question&Answers more detail:os