Click here to Skip to main content
Click here to Skip to main content
Go to top

Creating Multilingual and Localized Pages in .NET

, 14 Sep 2008
Rate this:
Please Sign up or sign in to vote.
Article describes how to create multilingual, localized pages in .NET

Introduction

Here I will discuss how to develop multilingual and localized pages in .NET web applications. The main problem with the multilingual application is reset the current culture, language each time page is postback because it may reset to the default language/culture. I will also discuss use of resource files for multilingual application and also approaches to localize images.

Description

Let us start this exercise in steps.

  1. Create your own base page class: The problem with multilingual application as I discussed earlier is that it might reset the culture back to the default during page postback. To tackle with this issue .NET provides us a method which is part of page life cycle to initialize culture. So we can write our own class inherited from System.Web.UI.Page class and override its InitializeCulture method as follows:
protected override void InitializeCulture()
{
    //get the culture information from wherever you want suppose it is a property
    //with your user class

    Thread.CurrentThread.CurrentCulture = 
        CultureInfo.CreateSpecificCulture(CurrentLoggedinUser.PreferredCulture);
    Thread.CurrentThread.CurrentUICulture = new 
        CultureInfo(CurrentLoggedinUser.PreferredCulture);

    base.InitializeCulture();
}

Now override each of your aspx page with your own class instead of Page class. And it will reset the current culture as per your requirement.

  1. Using resource file: Resource files are the .resx extension file where you can keep content of your web pages to choose according to the language. You should keep 1 resource file for each language your application support. Now the question is how to pick values from these resource files, no problem, its jus matter of couple of lines of code:
ResourceManager rm =new ResourceManager(“Name of resource file”,
    Assembly. GetExecutingAssembly());

Label1.Text=rm.GetString(“key1”);

To avoid few compile time error in above code add following namespace in your code

Using System.Resources;

Using System.Reflection;
  1. Localizing Images: For localizing images you can choose any one of two approaches. First keep of name of all images in the resource file and access image path like this:
imageButton1.ImageUrl= rm.GetString(“imagepath1”);

Other approach which I prefer is to keep all images of one language in one folder and keep name of that folder in your resource file but remember to keep same name for a image in all language.

imageButton1.ImageUrl= rm.GetString(“ImageFolder”) +”LoginImage.jpg”;

Summary

Here we have discussed about creating localized pages in .NET application. We discussed that how to set culture in each page trip. Then we discussed how to pick values from resource file and the we discusssed approaches for localizing images of your application. Hope it helps. Thanks.

License

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

Share

About the Author

dixit gaurav
Web Developer Nagarro Software Pvt Ltd Gurgaon India.
India India
No Biography provided

Comments and Discussions

 
GeneralNeed more detail PinmemberDonsw20-Jan-09 17:01 
GeneralMy vote of 2 PinmemberDonsw20-Jan-09 17:00 
GeneralMy vote of 2 PinmemberMember 196961510-Dec-08 1:39 

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 | Mobile
Web01 | 2.8.140916.1 | Last Updated 14 Sep 2008
Article Copyright 2008 by dixit gaurav
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid