Private SupportedLanguages As String() = {"en-us", "fr-fr"}
Public Const LANGUAGE_COOKIE_NAME As String = "UserLanguage"
Sub Application_AcquireRequestState(ByVal sender As Object, ByVal e As EventArgs)
Dim languageCookie As HttpCookie = Request.Cookies(LANGUAGE_COOKIE_NAME)
Dim language As String = String.Empty
If (languageCookie Is Nothing) Then
Dim userLanguages As String() = Request.UserLanguages
Dim index As Integer
For i As Integer = 0 To userLanguages.Length - 1
index = Array.IndexOf(SupportedLanguages, userLanguages(i))
If index >= 0 Then
language = SupportedLanguages(index)
Exit For
End If
Next
If language = String.Empty Then _
language = SupportedLanguages(0)
Response.Cookies.Add(New HttpCookie(LANGUAGE_COOKIE_NAME, language))
Else
language = languageCookie.Value
End If
Dim culture As CultureInfo = New CultureInfo(language)
System.Threading.Thread.CurrentThread.CurrentUICulture = culture
End Sub
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
SetLanguage("fr-fr")
End Sub
Protected Sub SetLanguage(ByVal language As String)
Response.Cookies(Global.ASP.global_asax.LANGUAGE_COOKIE_NAME).Value = language
Dim culture As CultureInfo = New CultureInfo(language)
System.Threading.Thread.CurrentThread.CurrentUICulture = culture
Server.Transfer(Request.Path)
End Sub