Posts Tagged ‘globalization’

Localization and Globalization in C#: Globalization

Thursday, March 19th, 2009

Like localization, globalization in .NET is easy. If you want your application to be globalization-aware you need to display all the date, time, currency and other data in the proper display format. Fortunately, every .NET Convert method has a built in IFormatProvider parameter you can use to specify the culture you want your globalization-aware data to be displayed in. In order to force yourself to use the IFormatProvider, you can use CODE_ANALYSIS in Visual Studio, or external FxCop application which does the same thing. This application inspects your code and suggest to you how you can improve it.

DateTime.Now.ToString(CultureInfo.CurrentCulture);

If the data you are working with is not going to be displayed to the user, for example, you want to save information into a file so you can load it later, you should not use the CurrentCulture as an IFormatProvider. If you save your settings using the “de-AT” culture, and then you try to load them using “en-US” culture you might end-up with the invalid data. For this purposes, you should use CultureInfo.InvariantCulture, since it is invariant to both localization and globalization settings.

DateTime.Now.ToString(CultureInfo.InvariantCulture);

Localization and Globalization in C#: Introduction

Wednesday, February 25th, 2009

.NET is equipped with powerful, yet simple, application localization and globalization mechanisms.

Localization is the process of translating resources to a specific culture. On the other hand, globalization is the process of designing applications that can adapt to different cultures. Basically, when you select the application language, you need to specify the culture the selected language is used in. For example, English language is used in United States, Canada and Great Britain, among other countries. Although, people in these countries are using the same language, their cultures are different (i.e.: date and time format differences, currency is different, etc.). There is a standard for designating the cultures. A list of currently available cultures can be found here.

In the heart of localization and globalization mechanism in the .NET framework is the System.Globalization namespace. In the heart of this namespace is the CultureInfo class with its static properties. Some of those properties are InvariantCulture, CurrentCulture, CurrentUICulture, etc.

CurrentCulture property has a lot to do with the Regional Settings in your Control Panel. Basically, Regional Settings in your Control Panel is the place where can you set how you want your date, time, currency and other stuff to appear in your Windows. CurentCulture static property reflects that setting.

On the other hand, CurrrentUICulture is in connection with the Windows itself. Most of us are using English version of Windows, to be more precise “en-US” version of Windows, but there are other Windows localizations available on the market. CurrentUICulture property reflects the Windows language.

In another words, if your Windows is in English (all messages, titles, captions, etc.), your CutureInfo.CurrentUICulture is “en-US”. This setting has nothing to do with the Regional Settings you have set in your Control Panel. Your CutlureInfo.CurrentCulture can be set to “fr-FR” on the “en-US” Windows. This setting will affect only date, time, currency and other display formats.