Introduction
Globalization, Localization concepts in ASp.Net enable developers and end users to enhance the web application with specific or generic culture content or information. Like Globalization enables developers to design and develop applications that function for multiple cultures and Localization enables for customizing your application for a given culture and locale. In this precise article and sample file attached having few techincal terms which are explained below.
Background
ASP.Net 2.0 can render the localized HTML for special browsers. It checks the "Accept-Language" HTTP header to identify the browser settings. To perform the localization, we can simply add the attributes for @Page or add globalization section in web.config file.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" Culture="auto" UICulture="auto" %>
Or
<!--// Web.config section under system.web-->
<globalization culture="auto" uiCulture="auto"/>
The differences between "Culture" and "UICulture" are Culture controls the formatting of dates, numbers, and currency whereas UICulture is for resource loading.
Using the code
I've made a sample to demonstrate the implementation of two cultures and languages Like, English and Arabic. Note : Arabic you'll find does not have any meanings, it is just for using Arabic language in ur application.
in this sample, there is a page named Default.aspx, which is inherited by the base page class managing the change in culture at user request. as the user presses the button to change in the culture Like English Or Arabic the base page class changes the current culture thread to the specified culture by the user.
protected void lnkEnglish_Click(object sender, EventArgs e)
{
this.CurrentCulture = "en-US";
base.InitializeCultures();
}
where as base class having the manual mechanism to change the contents on the web page to
the specified culture.
in Default2.aspx there is a master page, which contains two link buttons for
arabic and english. the change in the culture is managed by master with the same manual mechanism.
and in Default3.aspx file the culture is implemented by the generating the local Resource from
Visual studio Menu -> Tools -> Generate Local Resource. this option generates the local resource for
the current page with current page name like Default3.aspx.resx. I leave this page to readers to inherit
"cs">this page with master page(having two link buttons for English and Arabic) and just change the culture
by using the following methods.
protected void lnkEnglish_Click(object sender, EventArgs e)
{
base.UICulture = "en-US";
Session["UIc"] = "en-US";
InitializeCulture();
}
protected void lnkArabic_Click(object sender, EventArgs e)
{
base.UICulture = "ar-SA";
Session["UIc"] = "ar-SA";
InitializeCulture();
}
protected override void InitializeCulture()
{
try
{
Thread.CurrentThread.CurrentCulture = new CultureInfo(Session["UIc"].ToString());
Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture;
}
catch (Exception ex)
{
}
}
You'll see a differnce from other two pages that this implementation is automatic. you donot need to
do it manually as you've done in previous two pages.
NOTE : Uploaded are two files, One is having WebFiles and other contains a solution file.
plz change a soltuion file settings by editing it into a notepad according to ur system
local path for this project.