When you are developing a web site for international users, one questions instantly come to our mind which is how our web site going to support multiple language, currencies, date etc.? Thanks to ASP.Net 2.0, it made our task of making localized application simple and easier. Localization is the process of designing and developing a software product that function for multiple cultures having different language currencies, date and time. Asp.Net 2.0 has a incredibly good features to support localizaion. These are features are self explanatory and easy to use. A .Net web forms page have two culture values , Culture and UICulture. Culture is used to determine culture dependent function such as Date, Currency. So it is used for date formatting ,number formatting. UICulture values is used to determine which language the resources should load that is which UI string the resource should use. The two culture settings do not need to have same values. It may be different depending on the application. I will give you brief idea of developing application that support localization. For example, we want to develop a website which should support english and french language. Functionality of the web site will be same only difference will be the language in which information will be displayed on the pages of web site.
Setting Culture and UICulture
1. Through Web.Config
<configuration>
<system.web>
<globalization fileEncoding=”utf-8″ requestEncoding=”utf-8″ responseEncoding=”utf-8″ culture=”en-US” uiCulture=”frFR” /></system.web></configuration>
2. In Code-inline (aspx) Page
|
<%@ Page UICulture=”fr” Culture=”en-US” ….%> |
3. In Code-Behind (aspx.cs) Page
|
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture (“fr-FR”); |
Resources:
ASP.NET wont automatically translate the contents in one language to another language by using Culture. For this we need to put our language specific labels, messages, title in resources file and ASP.Net will load this information from resource file depending on the setting of UICulture and key provided to Resource Manager object. Each entry in the resource file will have a resource key which help us to identify and read the message from the resource fileResources represents embedded data such as strings or images, which can be retrieved during runtime and displayed in the user interface. Resource Management is a feature of .NET framework which is used to extract localized element from source code and to store them with a string key as resources . At runtime, ResourceManager class instance is used to resolve key to the original resource or localized version. Resources can be stored as an independent file or part of an assembly. ResourceWriter and resgen.exe can be used to create .resources file. To include .resources file inside an assembly use related compiler switch or Al.exe.
Create Resource Text Files:
In resource.en-US.txt
Test = Hello there, friend!In resource.fr-FR.txt
Test = Bonjour là, ami!
Generate .resources file:
Goto VisualStudio.Net command prompt and use resgen command utility to generate .resources file resgen resource.en-US.txt
resgen resource.fr-FR.txtThis commands will create .resources file.
In TestGlobalization.aspx Page
|
<asp:RadioButtonList id=”RadioButtonList1″ style=”Z-INDEX: 101; LEFT:144px; POSITION: absolute; TOP: 144px” runat=”server” |
In TestGlobalization.aspx.cs Page, on Page_Load Event
|
CultureInfo objCI = new CultureInfo ( RadioButtonList1 .SelectedValue .ToString ()) ; |
You can read details explaination of localization in Asp.Net 2.0 at following links
http://www.ondotnet.com/pub/a/dotnet/2005/08/08/localizingaspnet20.html?page=1
http://aspalliance.com/821
http://www.codeproject.com/KB/aspnet/localizationByVivekTakur.aspx