Advertisement
Shad0w

Untitled

Nov 19th, 2011
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ASP 1.16 KB | None | 0 0
  1. /// <summary>
  2. /// Sets a user's Locale based on the browser's Locale setting. If no setting
  3. /// is provided the default Locale is used.
  4. /// </summary>
  5. public static void SetUserLocale(string CurrencySymbol, bool SetUiCulture)
  6. {
  7.     HttpRequest Request = HttpContext.Current.Request;
  8.     if (Request.UserLanguages == null)
  9.         return;
  10.  
  11.     string Lang = Request.UserLanguages[0];
  12.     if (Lang != null)
  13.     {
  14.         // *** Problems with Turkish Locale and upper/lower case
  15.         // *** DataRow/DataTable indexes
  16.         if (Lang.StartsWith("tr"))
  17.             return;
  18.  
  19.         if (Lang.Length < 3)
  20.             Lang = Lang + "-" + Lang.ToUpper();
  21.         try
  22.         {
  23.             System.Globalization.CultureInfo Culture = new System.Globalization.CultureInfo(Lang);
  24.             if (CurrencySymbol != null && CurrencySymbol != "")
  25.                 Culture.NumberFormat.CurrencySymbol = CurrencySymbol;
  26.            
  27.             System.Threading.Thread.CurrentThread.CurrentCulture = Culture;
  28.  
  29.             if (SetUiCulture)
  30.                 System.Threading.Thread.CurrentThread.CurrentUICulture = Culture;
  31.         }
  32.         catch
  33.         { ;}
  34.     }
  35. }
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement