Mar 19 2006

CurrentCulture & CurrentUICulture

Category: ASP.NET 1.x | ASP.NET 2.0 - GeneralBil@l @ 13:10

There has been always a popular question on the ASP.NET forums about the difference between CurrentCulture and CurrentUICulture. I wanted to distinguish things in this post and make it clear once and for all.

  1. CurrentCulture and CurrentUICulture are both of type CultureInfo which is part of the  System.Globalization.
  2. CurrentCulture and CurrentUICulture are boh properties of the current thread represented as: System.Threading.Thread.CurrentThread.CurrentCulture and System.Threading.Thread.CurrentThread.CurrentUICulture
  3. CurrentCulture is used mainly to format the Dates, Currencies, etc ... For that reason it should be set specific. For instance, you need to set the CurrentCulture as:

    System.Threading.Thread.CurrentThread.CurrentCulture= new CultureInfo("ar-LB");

    We have set current culture to be a specific culture and mainly, Arabic - Lebanese. So make sure always to be specific in specifying the
    CurrentCulture
  4. CurrentUICulture is mainly used for language/text translations. So the ResourceManager is based upon the CurrentUICulture. It doesn't matter whether the culture set here is specific or neutral. For instance, either ar or ar-lb works fine with the CurrentUICulture:

    System.Threading.Thread.CurrentThread.CurrentCulture= new CultureInfo("ar"); // ar-lb

    Both work fine in this case.
  5. ASP.NET controls (Calendar for example) with built-in localization cannot use a neutral culture. When you want to make use of the built-in localization of ASP.NET Controls, make sure to specify a specific culture in the CurrentCulture.

Hope this post helps you clarify the differences between CurrentCulture and CurrentUICulture.

Regards 

Tags: ,

Comments are closed