This post will be about the globalization and localization techniques ASP.NET provides us. There are two types of resources which you can use in an ASP.NET page: global, which means they are accessible from all pages, and local, for each given page. First let’s see how to use global resources.
To enable them, add a special folder named App_GlobalResources. In this folder, you can insert whatever resource you’d like to use. Let’s insert a .resx file, this will be the default culture you’d use. Let’s call it GlobResx.resx. Add a key-value pair, for example HeaderText = Hello World. Now on a random .aspx page, define a Label control, and set its text property to <%$ Resources: GlobResx, HeaderText %>. Now you are done, when you run your site, you’ll see Hello World as the label’s text.
Now let’s take a further step. Create a file named GlobResx.en.resx into the App_GlobalResources folder. Add the same HeaderText entry, but now use the value: Hello for the English-speaking World! If your browser is set up to use the English culture, you’d see your label shows the new text.
Don’t let yourself fooled by the title, we’ll discuss the topics of Globalization here. You’ll need the System.Globalization and System.Threading namespaces and possibly Sysglobl.dll to build custom cultures.
A little terminology: today, culture will mean the language, currency, date-format, calendar, writing system and different names of a given group of people. There are two types of cultures: neutral, which only provides information of the language spoken, and specific culture, which provides information about the region/country. For example “es” means the Spanish neutral culture, and “es-MX” means the Mexican culture with the appropriate region information (such as the unit of currency, date format, etc.). There’s also a special culture, called Invariant culture. This one is associated with the English language, but not with any region/country. You’ll use this one when you need consistency across different cultures in your application.