0

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"  />
Eric
  • 695
  • 9
  • 25

1 Answers1

1

It does work for me. Lets check basics here:

  • do you have folder called App_LocalResources in your web project ?
  • in this folder you should have default resource file (assuming your master page is named MasterPage.Paster) there should be MasterPage.Master.resx (for english - default) and MasterPage.Master.nl-Nl.resx
  • both those files should be marked as "Embedded Resources" in properties
Ondrej Svejdar
  • 21,349
  • 5
  • 54
  • 89
  • * yes * I renamed it with the culture name. Probably shouldn't have done that, so I generated a new one. * they are. – Eric May 22 '14 at 15:58
  • Yes, that was it. I shouldn't have renamed the masterpage default resource file. Generating a new one, solved the problem. Big thanks, Ondrej!!! – Eric May 22 '14 at 16:00