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

Globalization in ASP.NET 2.0

By , 8 Mar 2011
 

Introduction

Globalization is the process of designing and developing applications which can be adapted to different languages. Globalization is the process of designing and developing a software product that functions for multiple cultures.

If you want your website to be accessible in several languages in different regions, you should globalize it.

Background

Globalization is a very efficient functionality that you can give to your website so that it can be adapted to different languages and regions.

A very good example you can see is the Google home page. There are different language options given below from which you can select one language and the whole site would adapt for that particular language.

How Would You Globalize Your Website in ASP.NET

Design your Page

Start Visual Studio 2005, go for a new website, name it ‘GloblizationEx’. First, design your website like a sample I have given below. Take 3 link buttons and a label. Change the text property of label to ‘Hello user let’s learn Globalization’ and change the text property of three link buttons to French, German, Russian.

Now make click event of LinkButton1 by double clicking on it. Go to LinkButton2 property select event tab, select ‘LinkButton1_Click’ for click event. Repeat this for LinkButton3.

Add Resources Files

Now, you have to add resources file to your website, but first add a New Folder to your website and named it ‘resources’. For this, just go to solution explorer, right click on root and select ‘New folder‘. Now right click to this resources folder and select ‘Add New Item..’ option, Add New Item dialog box will appears, select ‘Resource File’ and named it ‘strings.fr-FR.resx’. A message box will appear, click ‘No’ as given below:

Now a screen appears. You have to enter Name and value for your resource file.

Enter ‘msg’ for Name and ‘bonjour utilisateur apprenons globlization’ for value field. Don’t worry, this msg is only French conversion of your message that you had given at your home page. Repeat these steps for German and Russian, file name will be ‘strings.de-DE.resx’ and ‘strings.ru-RU.resx’ respectively. You can give value field for German and Russian as ‘hallo Benutzer lets lernen globlization’ and ‘@ hallo lernen globlization’ respectively. But Name field will be the same ‘msg’. Save all. A sample is given below:

Note: You can translate your messages using Google More>>Translate tab.

Generate ‘.resources’ files.

Now you have to generate ‘.resources’ file. For this you have to open visual studio command prompt, you can find it at ‘visual studio 2005>> Visual Studio Tools’ menu. As you start Visual Studio command prompt, cmd screen appears. You have to locate ‘resources’ folder, like if you are creating your website in C drive with name ‘GloblizationEx’, you have to locate like ‘c:\Globlization\resources’ now type command ‘resgen strings.fr-FR.resx’ for French resx file. Do it for German and Russian as ‘resgen strings.de-DE.resx’ and ‘resgen strings.ru-RU.resx’ respectively.

You can notice that .resources files are added to ‘resources’ folder.

Using the Code

You should use the following namespaces:

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Resources;
using System.IO;
using System.Globalization;

Now type the following code to click event (LinkButton1_Click) of LinkButton1.

protected void LinkButton1_Click(object sender, EventArgs e)
    {
        string lanName="";
        LinkButton lnkBtn=(LinkButton)sender;

        switch (lnkBtn.ID)
        {         
            case "LinkButton1":
                lanName = "fr-FR";
                break;
            case "LinkButton2":
                lanName = "de-DE";
                break;
            case "LinkButton3":
                lanName = "ru-RU";
                break;
        }
        System.Resources.ResourceManager rm = 
        ResourceManager.CreateFileBasedResourceManager
        ("strings", Server.MapPath("resources") + Path.DirectorySeparatorChar, null);
        CultureInfo cinfo = new CultureInfo(lanName);
        Label1.Text = rm.GetString("msg", cinfo);
    } 

Now just debug your website and click on ‘French’/’German’/’Russian’ link to change your welcome message.

History

  • 8th March, 2011: Initial version 

License

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

About the Author

Brijesh Kr
Instructor / Trainer TechnoCampus
India India
Member
MCTS, MCPD, MCA, GNIIT
More than 2.5 yrs of Experience in .NET Platform.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralThis is not globalisation.mvpPete O'Hanlon9 Mar '11 - 1:47 
You have not even begun to scratch the surface of what makes a globalised site. Where is your description of the use of culture specific formatting? Where have you covered designing fluid layouts that serve RTL as well as LTR cultures? What about imagery?

I'm not a stalker, I just know things. Oh by the way, you're out of milk.

Forgive your enemies - it messes with their heads

My blog | My articles | MoXAML PowerToys | Onyx


GeneralRe: This is not globalisation.memberOakman14 Mar '11 - 12:13 
No, it's not. He makes that clear. He's talking about globlization.
“The whole aim of practical politics is to keep the populace alarmed (and hence clamorous to be led to safety) by menacing it with an endless series of hobgoblins, all of them imaginary.” ~ H.L. Mencken

GeneralMy vote of 5memberSona s9 Mar '11 - 1:20 
Nice Article
GeneralMy vote of 2memberMember 1319238 Mar '11 - 21:58 
It's very easy sample
GeneralMy vote of 5memberr.s19878 Mar '11 - 18:51 
i read this code. its really fantastic........

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

Permalink | Advertise | Privacy | Mobile
Web03 | 2.6.130523.1 | Last Updated 9 Mar 2011
Article Copyright 2011 by Brijesh Kr
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid