locked
Changing Cultures RRS feed

  • Question

  • User1464674564 posted


    I have a site that needs to support 2 cultures, "en-US" and "fr-CA" an there needs to be a link at the bottom that can switch between the two cultures. To do this I store the current culture in a session variable and have a link button that changes the value. Then I override the pages InitializeCulture with the following

            protected override void InitializeCulture()
            {
                base.InitializeCulture();
    
                if (Session["PageCulture"] == null)
                {
                    Session["PageCulture"] = System.Threading.Thread.CurrentThread.CurrentCulture.ToString();
                }
                else
                {
                    System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo((string)Session["PageCulture"]);
                    System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo((string)Session["PageCulture"]);
                }
            }
        }


    This works except for validation errors that are stored in resource files. When I switch to a different culture the validation errors are always in the default culture. Does anyone know why?


    Also as a question of interest wouldn't changing the System.Threading.Thread.CurrentThread's culture change the culture for all clients running on that thread or does it do just the current request?

    Tuesday, August 10, 2010 4:24 PM

Answers

  • User-830258159 posted

    The validation error values are set at the time of initial page load.   When you are changing the culture.. its causing a post back and putting the culture information in session..  if you want the changes to reflect in the validation errors. you will have to reassign the error messages after the culture change. 




    Also when you change the culture, it gets changed for the current session and not for all other sessions.



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, August 11, 2010 1:33 AM