Click here to Skip to main content
15,881,618 members
Articles / Web Development / ASP.NET
Article

Globalization & Localization

Rate me:
Please Sign up or sign in to vote.
4.50/5 (2 votes)
9 Dec 2007CPOL1 min read 30.8K   15   2
implementing multiple culture with master page

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.

            //
            // Any source code blocks look like this
            //
        
protected void lnkEnglish_Click(object sender, EventArgs e)

{

this.CurrentCulture = "en-US";

//pageDiv.Attributes.Add("dir", "ltr");

base.InitializeCultures();

}
where as base class having the manual mechanism to change the contents on the web page to 
the specified culture.

<pre>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
<pre lang="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;

//base.InitializeCulture();

}

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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
Pakistan Pakistan
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralMy vote of 5 Pin
hsnfrz29-Aug-12 1:26
hsnfrz29-Aug-12 1:26 
GeneralGlobalization & Localization Pin
aminamaq24-Jan-09 21:24
aminamaq24-Jan-09 21:24 
thanks alot for this example

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.