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

Multilanguage Supporting Urdu and English

, 1 Dec 2011
Rate this:
Please Sign up or sign in to vote.
In this article, we discuss a way in which you could manage your site to support multiple languages.
Article.gif

Introduction

Do you like to support multi-languages to your website? In this article, we discuss a way in which you could manage your site to support multiple languages. We do not say that this piece of writing is the only way of achieving the goal, but this could be a good starting point. The code for this article is written in C# Visual Studio 2010.

Using the Code

//
protected override void InitializeCulture()
    {       
        string lang = string.Empty;
        try
        {
            lang = Request.Form["DdlLanguages"].ToString();
        }
        catch (Exception) { }


        if (lang != string.Empty)
        {
            SetCulture(lang, lang);           
        }        
       
        if (Session["MyUICulture"] != null && Session["MyCulture"] != null)
        {
            Thread.CurrentThread.CurrentUICulture = (CultureInfo)Session["MyUICulture"];
            Thread.CurrentThread.CurrentCulture = (CultureInfo)Session["MyCulture"];
        }
        base.InitializeCulture();
    }
     ...

Here we are overriding the InitializeCulture() function. This is called on initializing of page in which we inset the current culture as well as user interface culture properties.

//
protected void SetCulture(string name, string locale)
    {
        Thread.CurrentThread.CurrentUICulture = new CultureInfo(name);
        Thread.CurrentThread.CurrentCulture = new CultureInfo(locale);
       
        Session["MyUICulture"] = Thread.CurrentThread.CurrentUICulture;
        Session["MyCulture"] = Thread.CurrentThread.CurrentCulture;

        base.InitializeCulture();
    }
    ...

By changing the value of dropdown SetCulture function is called by the two arguments having almost the same values string name, and string locale, to set the CurrentUICulture and CurrentCulture properties by the newly selected language. At the end, save that culture in two different session variables Session["MyUICulture"] and Session["MyCulture"]. Finally, call the base function InitializeCulture().

Step by Step Guide

  1. Create an ASP.NET web site in Visual Studio 2010
  2. Add a page default.aspx 
  3. Add dropdown list box, calendar and label 
  4. Go to design view of your page, in tools menu and click on 'generate local resource' - it will create a file "Default.aspx.resx" in a system directory App_LocalResources
    To write in Urdu, follow these steps.
  5. To write in Urdu, go to control panel, Under Clock Language and Region, click on change keyboards or other input methods
  6. Click keyboard and language tab 
  7. Click change keyboards
  8. Click on add button and choose Urdu and click OK
  9. Click on the tab 'Advanced key settings' and select the language and click change key sequence
  10. Check the enable key sequence checkbox (remember the shortcut key) and press OK
  11. To work in Urdu phonetic keyboard, download it from http://urdu-phonetic-keyboard.findmysoft.com/download/ 
  12. Install it and follow step# 5-10
  13. Copy (Default.aspx.resx) and paste it in the same directory and rename it as (Default.aspx.ur-PK.resx)
  14. Open (Default.aspx.ur-PK.resx), change value of Label1Resource1.Text as you like to write in Urdu, press the short cut key which you set in keyboard settings i.e. (CTRL+0)
  15. Press CTL+F5 to run the project

History

  • 29th November, 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

Muhammad Shahid Rasul from Pakistan

Comments and Discussions

 
Questionyou did a really good job Pinmemberweb Designer25-Apr-14 14:24 
SuggestionUrdu Components for VB.NET and C# PinmemberNaseem_Amjad31-Aug-13 6:03 
QuestionMy Vote of 4 Pinmemberfaizan Akhtar Shaikh7-Dec-11 0:55 
AnswerRe: My Vote of 4 PinmemberMuhammadShahidRasul8-Dec-11 18:18 
GeneralMy vote of 3 PinmemberSercanOzdemir1-Dec-11 14:00 

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
Web02 | 2.8.140721.1 | Last Updated 1 Dec 2011
Article Copyright 2011 by MuhammadShahidRasul
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid