Click here to Skip to main content
15,891,828 members
Articles / Programming Languages / C#
Article

Multilanguage Supporting Urdu and English

Rate me:
Please Sign up or sign in to vote.
4.00/5 (2 votes)
1 Dec 2011CPOL2 min read 22.1K   1.1K   9   5
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

C#
//
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.

C#
//
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)


Written By
Pakistan Pakistan
Muhammad Shahid Rasul from Pakistan

Comments and Discussions

 
Questionyou did a really good job Pin
Faysel Kedir25-Apr-14 14:24
Faysel Kedir25-Apr-14 14:24 
SuggestionUrdu Components for VB.NET and C# Pin
Naseem_Amjad31-Aug-13 6:03
Naseem_Amjad31-Aug-13 6:03 
QuestionMy Vote of 4 Pin
faizan Akhtar Shaikh7-Dec-11 0:55
faizan Akhtar Shaikh7-Dec-11 0:55 
AnswerRe: My Vote of 4 Pin
MuhammadShahidRasul8-Dec-11 18:18
MuhammadShahidRasul8-Dec-11 18:18 
GeneralMy vote of 3 Pin
SercanOzdemir1-Dec-11 14:00
SercanOzdemir1-Dec-11 14:00 

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.