Click here to Skip to main content
Click here to Skip to main content

Globalization & Localization

, 9 Dec 2007 CPOL
Rate this:
Please Sign up or sign in to vote.
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)

Share

About the Author

Aqeel Khandwala
Web Developer
Pakistan Pakistan
No Biography provided

Comments and Discussions

 
GeneralMy vote of 5 Pinmemberhsnfrz29-Aug-12 2:26 
GeneralGlobalization & Localization Pinmemberaminamaq24-Jan-09 22:24 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.141216.1 | Last Updated 10 Dec 2007
Article Copyright 2007 by Aqeel Khandwala
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid