Strange Issue with localization RRS feed

  • Question

  • User-1696118602 posted

    Hey all,

    I'm having a strange isssue with localization.  I have a website that is going to be in English and French.  I have my resource files set up and everything works when i set my browser to French or English.  However I do have a DDL on the main page where the user can select the language the want to use for the site.  This gets stored in the session.  The issue with going this route is that even though the've selected French only some of the content is appearing in French.  I'm not sure why it works when the browser default is French and it doesn't work when they use the DDL to select French.  Any thoughts would be greatly appreciated.

    Wednesday, October 26, 2011 11:14 AM

All replies

  • User1519636740 posted


    refer: http://msdn.microsoft.com/en-us/library/c6zyy3s9.aspx

    Friday, October 28, 2011 5:33 AM
  • User-1696118602 posted

    Thanks but this doesn't help my issue.

    Friday, October 28, 2011 12:59 PM
  • User-1696118602 posted

    Some further explanation may help.

    Scenario 1

    Users browser settings are set to french

    Results in:


    Scenario 2

    User selects Language from DropDown

    Results in:


    Source Code:

    Page with DDL

        Protected Sub ddlLanguage_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlLanguage.SelectedIndexChanged
            If Page.IsPostBack Then
                'if the session differs from the value in the ddl, the session-object is changed and the cookie is created
                If Not Session("MyCulture") = ddlLanguage.SelectedValue Then
                    'Set the new culture
                    Session("MyCulture") = ddlLanguage.SelectedValue
                End If
                'Reload the page so that the content refreshes.
            End If
        End Sub
        Protected Sub SaveLanguageCheckbox_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles SaveLanguageCheckbox.CheckedChanged
            If Page.IsPostBack Then
                Dim aCookie As New HttpCookie("Settings")
                If SaveLanguageCheckbox.Checked Then
                    aCookie.Values("languagePref") = Session("MyCulture")
                    aCookie.Values("savePref") = SaveLanguageCheckbox.Checked
                    aCookie.Expires = System.DateTime.Now.AddDays(365)
                    aCookie = New HttpCookie("Settings")
                    aCookie.Expires = DateTime.Now.AddDays(-1D)
                End If
            End If
        End Sub
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            If Not Page.IsPostBack Then
                'Check to see if we have a cookie
                If Not Request.Cookies("Settings") Is Nothing Then
                        'If a cookie exists, set the session-object with the data from the cookie.
                        Session("MyCulture") = Server.HtmlEncode(Request.Cookies("Settings")("languagePref"))
                        SaveLanguageCheckbox.Checked = CBool(Server.HtmlEncode(Request.Cookies("Settings")("savePref")))
                    Catch ex As Exception
                    End Try
                End If
                If Not Session("MyCulture") Is Nothing Then
                    'Set the Language dropdown to the perfered language
                    ddlLanguage.SelectedValue = Session("MyCulture")
                End If
            End If
        End Sub



    Base Page inerhited by all pages

            Protected Overrides Sub InitializeCulture()
                'retrieve culture information from session
                Dim SelectedCulture As String = Convert.ToString(Session("MyCulture"))
                'check whether a culture is stored in the session
                If Not String.IsNullOrEmpty(SelectedCulture) Then
                    Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(SelectedCulture)
                    Thread.CurrentThread.CurrentUICulture = New CultureInfo(SelectedCulture)
                End If
            End Sub
    Hope this helps.
    Friday, October 28, 2011 1:57 PM