How to Create MultiLanguage WebSite in Asp.net



Here we will Create Multilanguage Webpage using Globalization and Localization in dot net. I have create Normal Page to Show you How to create it in your Webpage.

A multi-language site is a single website that’s reproduced and published in more than one language. Most of the content on the site is the same but is localized to reflect the language and culture of customers in various regions. As you can imagine, producing and maintaining a website with multiple language variants can be difficult and time-consuming. The SharePoint Online variations feature helps to simplify the task by automating page and site creation for each language and locale. 

It uses a source-target paradigm that enables you to author once and publish broadly with minimal setup time.

What is Globalization and Localization?
Globalization is a process of designing applications intended for users of different languages across the Globe while Localization is a process of designing the application so that it can display contents in the language of the user.

What is Language and Locale?
Language means the broader category of spoken languages i.e. English, French, etc. Now English is spoken in United Kingdom as well as United States but these both countries have their own vocabulary of English language which is known as Locale.
The Culture name for United Kingdom English is en-GB while for United States is en-US.

ASP.Net Global and Local Resources
ASP.Net has two set of Resource files i.e. Global and Local Resource files.

Global Resources
These resource files can be accessed on all pages throughout the applications.

Local Resources
These resource files are unique to each page and can be used only on that particular page.

This is a useful and simple tutorial to create a multi-language ASP.NET website. Following these steps, you will be able to create a good user interface multi-language website.

CODE:
<div>
   <table class="style1">
   <caption>
    <asp:Label ID="lblheader" runat="server" Font-Bold="True" Font-Size="Large" ForeColor="#FF66FF" Text="Label"></asp:Label>
   </caption>
     <tr>
     <td align="right">
     <asp:Label ID="lblabtme" runat="server" Font-Bold="True" ForeColor="#0066FF" Text="Label"></asp:Label>
     </td>
     <td>
<asp:Label ID="lbldesc" runat="server" Font-Bold="True" Text="Label"></asp:Label>
     </td>
     </tr>
     <tr>
     <td>&nbsp; </td>
     <td>
     <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="English" />
     &nbsp;&nbsp;
     <asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="Hindi" />
     &nbsp;&nbsp;
     <asp:Button ID="Button4" runat="server"  Text="Gujrati"
     onclick="Button4_Click" />&nbsp;&nbsp;
     <asp:Button ID="Button3" runat="server" OnClick="Button3_Click" Text="Marathi" />
     <br />
     </td>
     </tr>
     </table>
    </div>

Name Spaces:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Globalization;
using System.Resources;
using System.Threading;
using System.Reflection;

CODE BEHIND:
ResourceManager rm;
        CultureInfo 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);
            }

        }
        private void LoadString(CultureInfo ci)
        {

            lblabtme.Text = rm.GetString("AboutMe", ci);
            lbldesc.Text = rm.GetString("Desc", ci);
            Button1.Text = rm.GetString("Eng", ci);
            lblheader.Text = rm.GetString("Header", ci);
            Button2.Text = rm.GetString("Hindi", ci);
            Button3.Text = rm.GetString("Marathi", ci);
            Button4.Text = rm.GetString("Gujrati", ci);
        }

        protected void Button1_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("hi-IN");
            LoadString(Thread.CurrentThread.CurrentCulture);
        }

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

        protected void Button4_Click(object sender, EventArgs e)
        {
            Thread.CurrentThread.CurrentCulture = new CultureInfo("gu-IN");
            LoadString(Thread.CurrentThread.CurrentCulture);
        }

Now go to your Application right click and Add>Add ASP.Net Folder>Add_GlobalResources Folder in your Webpage.

Now Select Add_GlobalResources Folder and Add New Item. Resource1.resx add in Global Resources. Here I have created.

Strings.en-US.resx, Strings.gu-IN.resx, Strings.hi-IN.resx, Strings.mr-IN.resx, Strings.resx
In each File we to add Word wise Communication it means particular word with meaning and translation word. I have created like this.

Strings.resx
AboutMe
About Me
Desc
Hi, I'm Umesh Patel working on ASP.NET,C# and SQL Server from last two years in Ahmedabad
Eng
English
Gujrati
ગુજરાતી
Header
Localization In ASP.NET
Hindi
हिंदी
Marathi
मराठी

Strings.en-US.resx
AboutMe
About Me
Desc
Hi, I'm Umesh Patel working on ASP.NET,C# and SQL Server from last two years in Ahmedabad
Eng
English
Gujrati
ગુજરાતી
Header
Localization In ASP.NET
Hindi
हिंदी
Marathi
मराठी

Strings.gu-IN.resx
AboutMe
મારા વિશે
Desc
હાય, હું ઉમેશ પટેલ છું. અમદાવાદમાં છેલ્લા બે વર્ષ થી C # અને SQL સર્વર પર કામ છું.
Eng
ઇંગલિશ
Gujrati
ગુજરાતી
Header
ASP.NET સ્થાનિકીકરણ
Hindi
હિન્દી
Marathi
મરાઠી

Strings.hi-IN.resx
AboutMe
मेरे बारेमें
Desc
नमस्कार मैं  उमेश पटेल अहमदाबाद से हूँ. मैं यहाँ पे २ साल से C #,ASP.Net और SQL server पे  काम करता हूँ.
Eng
English
Header
Asp.Net में भाषा परिवर्तन
Hindi
हिंदी
Marathi
मराठी

Now run your Webpage and See you get Different button for translation in Language click on each one and enjoy your translation.

Related Posts

Previous
Next Post »

Thanks for comments.....