I am building a website with multiple language support. For this I have a link button on my master page.
I have created a new base class to inherit from. I have set the CurrentUICulture and CurrentCulture in the Global.asax file. I have created resource files of the masterpage. I have set the globalisation line in the webconfig file. Both culture and uiculture as set to "auto"
My master page is called "masterpage.master"
I have two resource files: masterpage.master.en-gb.resx
and masterpage.master.nl-nl.resx
. (I also tried with en-GB and nl-NL)
I created the masterpage initially in English. I use a cookie to store the chosen language. By default the cookie will be set to "en-GB" but for testing I set it to "nl-NL".
The cookie is created and with testing I saw the culture is being set to nl-NL
.
Yet.... the link-buttons text is not changing. It shows the en-GB text and not the nl-NL text.
What have I missed? How does the website select the right resx file? Is that done automatically based on the language and country setting in the file name or do I have to point that out?
The markup of the link button:
<asp:LinkButton ID="lbCHangeLanguage" runat="server" CssClass="lbCHangeLanguage" OnClientClick="javascript:return confirm('If you continue any unsaved changes will disappear!\n\nPress OK to continue.')" meta:resourcekey="lbCHangeLanguageResource1" Text="CHANGE LANGUAGE"></asp:LinkButton>
In global.asax:
Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
' Fires at the beginning of each request
Dim myLangCookie As HttpCookie
myLangCookie = Request.Cookies.Get("FASTLANG")
If myLangCookie Is Nothing Then
myLangCookie = New HttpCookie("FASTLANG")
myLangCookie.Values.Add("language", Languages.Dutch)
myLangCookie.Secure = False
If Request.Url.OriginalString.Contains("localhost") = False Then myLangCookie.Secure = True
If Request.Url.OriginalString.ToLower.Contains("fasttest") = True Then myLangCookie.Secure = False
myLangCookie.Expires = Now.AddYears(50)
Response.Cookies.Add(myLangCookie)
End If
Dim myLang As String = myLangCookie.Values("language")
Thread.CurrentThread.CurrentUICulture = New Globalization.CultureInfo(myLang)
Thread.CurrentThread.CurrentCulture = New Globalization.CultureInfo(myLang)
End Sub
in web.config:
<globalization enableClientBasedCulture="true" culture="auto" uiCulture="auto" requestEncoding="utf-8" responseEncoding="utf-8" />