Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Multilanguage Supporting Urdu and English

0.00/5 (No votes)
1 Dec 2011 1  
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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here