How to change CurrentCulture at runtime?

前端 未结 3 2184
滥情空心
滥情空心 2020-11-29 10:47

I need to change cultures at runtime according to resource files for each culture.

I need to change the attributes of the controls in my form, according to two cultu

3条回答
  •  余生分开走
    2020-11-29 11:33

    max set me on the right path , nothing i haven't come across before , but it did help me make a minor adjustment to the msdn documentation on the matter :

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

        string defaultLanguage = Thread.CurrentThread.CurrentUICulture.ToString();                         
        protected void Page_Load(object sender, EventArgs e)
        {
    
        }
    
        protected override void InitializeCulture()
        {
            if (Request.Form["ListBox1"] != null)
            {
                String selectedLanguage = Request.Form["ListBox1"];
                UICulture = selectedLanguage;
                Culture = selectedLanguage;
    
                Thread.CurrentThread.CurrentCulture = new CultureInfo(selectedLanguage);
                Thread.CurrentThread.CurrentUICulture = new CultureInfo(selectedLanguage);
            }
            else
            {
                Thread.CurrentThread.CurrentCulture = new CultureInfo(defaultLanguage);
                Thread.CurrentThread.CurrentUICulture = new CultureInfo(defaultLanguage);
            }            
            base.InitializeCulture();
        }   
    

    the list box contains different cultures the first and selected one is also the default culture , which i save on the page load , on other loads it as no effect because the listbox already as a value .

提交回复
热议问题