Developing multilingual applications in ASP.NET (Part - I)
Developing a multilingual applications always requires careful thought on the
method used to implement multilingual support. .NET provides some easy to
implement features that help in the overall process. In this part of the article
we will see the commonly used terms in this context and how ASP.NET provides out
of the box support for developing multilingual applications.
The classic way
Let us assume that you want to develop a web site in two different languages - English and Marathi. Naturally, all the content of these sites will be in the respective language. The content includes static text, form labels, prompts, error messages and similar things. In addition you would also like to take care of things such as date formats and number formats.
Typically you will choose one of the following approaches to develop such web sites:
You will develop all together separate pages for English version and Marathi version. The advantage of this method is that you have two distinct sets of pages. You can host them easily in two separate virtual roots or folders. The biggest drawback of this method is that
keeping both the sets in sync even after a minor change is very difficult. Maintaining or extending such sites is a difficult task.
You can store all the content in different languages in database tables. At run time you will retrieve the content corresponding to a language from this table. Similarly, based on the language chosen you will format date/time and numbers. This approach solves the problem to a large extent but still requires more coding and database storage.
You store all the content in resource files.
A resource is a non-executable data that is required by the application and is deployed along with the application. e.g. Bitmaps, icons, cursors, screen labels.
However, for traditional VB/ASP developer creating and consuming resource files
was not an easy task.
Before going in details of how to create resources, however, we need to
understand what is meant by "globalization", "localization" and "culture" in
Globalization is a process of identifying all the parts of your application
that need to be different for respective languages and separate them from the
Localization is process of creating and configuring your application for a
A culture is the combination of the language that you speak and the
geographical location you belong to. It also includes the way you represent dates, times
and currencies. A culture is represented as shown in the following
The first culture represents English language being spoken in US where as the
second culture represents English culture being spoken in Great Briton.
To work with culture information .NET provides a class called CultureInfo
that resides in System.Globalization namespace. The culture is set at thread
level so you also need to work with Thread class from System.Threading
namespace. Finally, for working with resources you need to use classes from
Get or set information about user culture
The current culture of a user can be retrieved by using CultureInfo.CurrentCulture property
of the class.
The culture can be set for a thread using Thread.CurrentThread.CurrentCulture property.
Dim ci as CultureInfo
Following example shows how to set culture information:
Dim ci as CultureInfo
Thread.CurrentThread.CurrentCulture = ci
In the above example since we set the culture to "en-GB" and date format used
in Great Briton is dd/MM/yyyy you will get the out in that format.
Setting culture for a page
You can very easily set culture for a single ASP.NET page by setting the
Culture attribute of the @Page directive.
<%@ Page language="c#" Culture="mr-IN"%>
Here, we set the culture for the page to mr-In (Marathi - India). If you now
put a calendar web control on the web form then at run time it will look like
Setting this property at page level automatically set the culture for current
thread. So, all the dates and number formats are displayed according to that
culture. You can check that by outputting current date via Response.Write
Setting culture at web application level
You can also set the culture for entire web application using web.config
file. The web.config <globalization> section allows you to do that. Following
example shows the markup:
<globalization culture="en-GB" />
In the Part - I of the series we saw how .NET provides easy to use classes
and configuration settings that you can use to develop multilingual
applications. In the next part we will see how to create and consume resource
files in .NET.