Click here to Skip to main content
15,860,943 members
Articles / Web Development / ASP.NET
Article

Satellite Assembly Demo by Using 12 Languages in C#

Rate me:
Please Sign up or sign in to vote.
2.86/5 (23 votes)
5 Apr 2007CPOL1 min read 43.7K   712   26   8
This demo is nothing new. It just shows the usage of localization using resource files for 12 languages.

Introduction

Hi everyone, this is my second article on The Code Project. Like the first one, I expect some feedback from you for this article as well. Thank you in advance!

Here I have worked on the localization concepts that have been introduced in .NET 2.0. But these concepts are nothing new.

Using the Code

I will list the methods with some brief explanation. I am not following Best Practices in Code Design. Since the concepts are not new, I have not explained much.

ASP.NET
<asp:DropDownList ID="DropDownList1" runat="server" Width="161px" AutoPostBack="True">
                <asp:ListItem Value="en-US">Default</asp:ListItem>
                <asp:ListItem Value="ar-AE">Arabic</asp:ListItem>
                <asp:ListItem Value="fr-FR">French</asp:ListItem>
                <asp:ListItem Value="de-DE">German</asp:ListItem>
                <asp:ListItem Value="it-IT">Italian</asp:ListItem>
                <asp:ListItem Value="pt-PT">Portuguese</asp:ListItem>
                <asp:ListItem Value="ru-RU">Russian</asp:ListItem>
                <asp:ListItem Value="el-GR">Greek</asp:ListItem>
                <asp:ListItem Value="hi-IN">Hindi</asp:ListItem>
                <asp:ListItem Value="ja-JP">Japanese</asp:ListItem>
                <asp:ListItem Value="ta-IN">Tamil</asp:ListItem>
</asp:DropDownList>

Here, I have first added 12 languages in the dropdownlist.

Then, I have added a div in which the text is inserted as ASP literal control.

ASP.NET
<asp:Literal ID="Literal1" runat="server" Text="<%$ Resources:Resource, Language%>"> 
</asp:Literal>: 
<asp:Literal ID="Literal2" runat="server" 
	Text="<%$ Resources:Resource, Language_Name%>"> 
</asp:Literal> 

Below this, I added a Label in which the text changes when a button is clicked. This is to show how to change the culture on a button click.

The design of the page will be:

Screenshot - design.gif

Now the code that is written in code behind:

C# provides an overridden method called InitialCulture(). In this method, we wrote the following code so that whenever the page is loaded, this method is invoked.

C#
protected override void InitializeCulture()
{
      string culture = Request["DropDownList1"];
      if (culture == null)
      {
         culture = "en-US";
      }
      Thread.CurrentThread.CurrentUICulture = new CultureInfo(culture);
      Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(culture);
}

In the Click event of the button, we write the following code:

C#
protected void Button1_Click(object sender, EventArgs e)
{
        Label1.Text = Resources.Resource.Welcome;
}

Output

Screenshot - output1.jpg

Screenshot - output2.jpg

Screenshot - output3.jpg

Screenshot - output4.jpg

Screenshot - output5.jpg

Points of Interest

The code is very simple and easy to write. Thus we can implement a resource file for any number of cultures.

In my next article, you will see how we can read the resource contents by using Resource file readers and how to edit the resource contents by treating resource files as an XML File.

Conclusion

If you find this article useful, I will appreciate your feedback. Thank you.

Expect more from me SOON!

History

  • 5th April, 2007: Initial post

License

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


Written By
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
Generalgood but Not Complete Pin
jainpr17-May-11 23:33
jainpr17-May-11 23:33 
GeneralMy vote of 1 Pin
Elmar de Koning1-Dec-10 22:20
Elmar de Koning1-Dec-10 22:20 
GeneralMy vote of 1 Pin
anant.sinha10-Feb-10 10:44
anant.sinha10-Feb-10 10:44 
GeneralGot my 5 for "TAMIL" Pin
Nagaraj Muthuchamy25-Feb-09 23:04
professionalNagaraj Muthuchamy25-Feb-09 23:04 
GeneralA very Goood Article Pin
Member 448984518-Dec-08 19:04
Member 448984518-Dec-08 19:04 
GeneralGood Article Pin
Ganesan Sankaran16-Oct-07 2:40
Ganesan Sankaran16-Oct-07 2:40 
Generalgood example Pin
code_proj_18-May-07 15:40
code_proj_18-May-07 15:40 
QuestionNice but, now what? Pin
root@ccess7-Apr-07 0:27
root@ccess7-Apr-07 0:27 

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.