Localization Like the Pros—CurrentCulture and CurrentUICulture

Microsoft .NET Framework, ADO.NET, ASP.NET, SQL Server, Visual C#, Visual Studio Developer Training


Jump to: navigation, search
CSharp-Online.NET:Articles
C# Articles

Localize Like the Pros

© 2004 Wiley Publishing, Inc.

CurrentCulture and CurrentUICulture

Setting cultures, you have to differentiate between a culture for the user interface and a culture for the number and date formats. Cultures are associated with a thread, and with these two culture types, two culture settings can be applied to a thread. Setting the culture with the thread, the Thread class has the properties CurrentCulture and CurrentUICulture. The property CurrentCulture is for setting the culture that is used with formatting and sort options, whereas the property CurrentUICulture is used for the language of the user interface.

Users can change the default setting of the CurrentCulture using the Regional and Language options in the Windows Control Panel (see Figure 17-3). With this configuration, it is also possible to change the default number, the time, and the date format for the culture.

The CurrentUICulture does not depend on this configuration. The CurrentUICulture setting depends on the language of the operating system. There is one exception: if a multi-language user interface (MUI) is installed with Windows XP or Windows 2000, it is possible to change the language of the user interface with the regional configuration, and this influences the property CurrentUICulture.


Image:557599-fg1703.jpg
Figure 17-3


These settings make a very good default, and in many cases, there is no need for changing the default behavior. If the culture should be changed, that can easily be done by changing both cultures of the thread to the Spanish culture as shown in this code snippet:

System.Globalization.CultureInfo ci = new 
   System.Globalization.CultureInfo("es-ES");
System.Threading.Thread.CurrentThread.CurrentCulture = ci;
System.Threading.Thread.CurrentThread.CurrentUICulture = ci;

Having learned about setting the culture, we are going to discuss number and date formatting as is influenced by the CurrentCulture setting.


Previous_Page_.gif Next_Page_.gif


Personal tools