Changing the locale of the browser

Last post 11-05-2009 5:14 AM by ratish_shriyan. 4 replies.

Sort Posts:

  • Changing the locale of the browser

    11-04-2009, 7:33 AM
    • Member
      18 point Member
    • jovenatheart
    • Member since 08-14-2006, 9:15 AM
    • Posts 24

    hi all,

    I need some help. I'm doing a dual-lingual application with resource files and I must allow the user to change the language at the click of a button.

    So, I have my resource files with the strings of the various languages but i'm not able to get the browser to pick up the new locale that I specified.

    Here's how I tried to do it:

    // This is a function in a generic Utility.cs class
    public static void setLocale(string newLocale){
            
            try
            {
                    System.Threading.Thread.CurrentThread.CurrentCulture =
                                       new System.Globalization.CultureInfo(newLocale);
                }
                catch (Exception ex)
                { 
                    // write to log file
                }
        }
    
    
    //the following codes is done everytime a page is loaded (postback or not).
                base.InitializeCulture();
    
    
    // this is the code in my button
    protected void lnkLanguage_Click(object sender, EventArgs e)
        {
            if (lblLanguage.Text == "")
            {
                lblLanguage.Text = "ch";
                Utility.setLocale("zh-HK");
            }
            else
            {
                lblLanguage.Text = "";
                Utility.setLocale(SecuredSession.Culture);
            }
        }


    what am I doing wrong?? or should i be doing it another way??

    Thanks in advance

  • Re: Changing the locale of the browser

    11-04-2009, 7:48 AM
    • Contributor
      2,194 point Contributor
    • ratish_shriyan
    • Member since 10-05-2009, 4:55 AM
    • A D I T I Technologies, Bangalore
    • Posts 308

    Hi,

    Guess you need to set the UI culture as well, like this,

    System.Threading.Thread.CurrentThread.CurrentCulture =   new System.Globalization.CultureInfo(newLocale);

    System.Threading.Thread.CurrentThread.CurrentUICulture =   new System.Globalization.CultureInfo(newLocale);

    Which will affect the resources that are loaded. CurrentCulture would affect the results of the functions such as Date, Currency formatting.

    Hope this helps!



    Knowledge Is Power
  • Re: Changing the locale of the browser

    11-04-2009, 7:51 AM
    • Contributor
      2,772 point Contributor
    • thirumaran007
    • Member since 03-14-2007, 5:39 AM
    • India
    • Posts 571
  • Hi Friend,
  • please add the bold marked line in your code..it will work
  • // This is a function in a generic Utility.cs class   
  • public static void setLocale(string newLocale){   
  •            
  •         try  
  •         {   
  • System.Threading.Thread.CurrentThread.CurrentCulture =   
  •                                    new System.Globalization.CultureInfo(newLocale);
  •                 System.Threading.Thread.CurrentThread.CurrentUICulture=   
  •                                    new System.Globalization.CultureInfo(newLocale);   
  •             }   
  •             catch (Exception ex)   
  •             {    
  •                 // write to log file   
  •             }   
  •     }   
  •   
  • With Friendly,
    Thirumaran

    Please remember to click "Mark as Answer" on this post if it helped you
  • Re: Changing the locale of the browser

    11-05-2009, 2:49 AM
    • Member
      18 point Member
    • jovenatheart
    • Member since 08-14-2006, 9:15 AM
    • Posts 24

    thanks for the quick response but it didn't seem to help. Cry 

  • Re: Changing the locale of the browser

    11-05-2009, 5:14 AM
    Answer
    • Contributor
      2,194 point Contributor
    • ratish_shriyan
    • Member since 10-05-2009, 4:55 AM
    • A D I T I Technologies, Bangalore
    • Posts 308

    Hi,

    It depends on how you have implemented globalization, I would suggest you to go through the following MSDN article and double check whether you have the followed the right steps,

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

    Good Luck!


    Knowledge Is Power
Page 1 of 1 (5 items)