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

Tagged as

Create Multi Language Web-Site in ASP.NET

, 28 Mar 2012 CPOL
Rate this:
Please Sign up or sign in to vote.
Create a multi-language website in ASP.NET.

Step 1: Start a new web site with C# and give it the Name Multilanguage website. It will give you a Default.aspx and Default.aspx.cs files.

Step 2: Now Design the form by putting three labels and three buttons on the form; set the id for the label as well as the button.

Step 3: Now go to Solution Explorer window and add a "App_GlobalResources" folder to your project by right clicking and selecting "Add ASP.NET Folder" option. It will add "App_GlobalResources" folder to your project. Now here right click and add Resource File and give it the name "Strings.resx"; it will add a resource file.

Step 4: Open that "String.resx" file and add a name to it and a value that you want on the first page load. We will give some English values here for the first time page load. Here we will add some fields like AboutMe, Desc, Header, Eng, Hindi, Marathi and also give some default values like About Me, Hi, Localization In Asp.Net and the two values for Hindi and Marathi taken from gmail option.

Step 5: Like in Step 4, create three more files for English, Hindi and Marathi and give the name with culture code like Strings.en-US.resx, Strings.hi-IN.resx, Strings.mr-IN.resx respectively and add same name and the different values with respect to language.

Step 6: Now open the code file of Default page and import the namespaces given bellow.

using System.Globalization;
using System.Resources;
using System.Threading;
using System.Reflection;

Step 7: Now in global declaration section of the .cs file, create an instance of the ResourceManager and CultureInfo classes.

.CS code:
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Globalization;
using System.Resources;
using System.Threading;
using System.Reflection;

public partial class _Default : System.Web.UI.Page 
{
    ResourceManager rm;
    CultureInfo ci;
    private void LoadString(CultureInfo ci)
    {

   Label1.Text = rm.GetString("AboutMe", ci);
     Label2.Text = rm.GetString("Desc", ci);
     Button1.Text = rm.GetString("Hindi", ci);
   Label3.Text = rm.GetString("Header", ci);
   Button2.Text = rm.GetString("Marathi", ci);
        Button3.Text = rm.GetString("Eng", ci);
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
            rm = new ResourceManager("Resources.Strings", 
                     System.Reflection.Assembly.Load("App_GlobalResources"));
            ci = Thread.CurrentThread.CurrentCulture;
            LoadString(ci);
        }
        else
        {
            rm = new ResourceManager("Resources.Strings", 
                     System.Reflection.Assembly.Load("App_GlobalResources"));
            ci = Thread.CurrentThread.CurrentCulture;
            LoadString(ci);
        }

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Thread.CurrentThread.CurrentCulture = new CultureInfo("hi-IN");
        LoadString(Thread.CurrentThread.CurrentCulture);
    }
    protected void Button3_Click(object sender, EventArgs e)
    {
        Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
        LoadString(Thread.CurrentThread.CurrentCulture);
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        Thread.CurrentThread.CurrentCulture = new CultureInfo("mr-IN");
        LoadString(Thread.CurrentThread.CurrentCulture);
    }
}

License

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

Share

About the Author

hi
Currently I am working on Asp.net and sql Server 2005
just having 1+ year experianced!

Comments and Discussions

 
QuestionHow make multi language site with masterpages in .net using Global.asax file Pinmemberberkut200619-Jun-13 15:35 
GeneralMy vote of 5 PinmemberAytha13-May-13 22:40 
Questionupdate panel issue during multilanguage using asp.net Pinmemberamruta khare7-Oct-12 21:02 
GeneralMy vote of 5 PinmemberAnuj Banka17-May-12 23:39 
QuestionIT IS GOOD Beginners.Good Job !!! :) PinmemberAnuj Banka17-May-12 23:38 
Questionnon-serious PinmemberMohammad_Denmark3-Apr-12 6:55 
AnswerRe: non-serious Pinmemberchetan virkar4-Apr-12 19:44 

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 | Terms of Use | Mobile
Web02 | 2.8.141223.1 | Last Updated 28 Mar 2012
Article Copyright 2012 by chetan virkar
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid