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

Satellite Assembly Demo by Using 12 Languages in C#

, 5 Apr 2007
Rate this:
Please Sign up or sign in to vote.
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: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: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.

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:

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)

Share

About the Author

No Biography provided

Comments and Discussions

 
Generalgood but Not Complete Pinmemberjainpr17-May-11 23:33 
GeneralMy vote of 1 PinmemberElmar de Koning1-Dec-10 22:20 
GeneralMy vote of 1 Pinmemberanant.sinha10-Feb-10 10:44 
GeneralGot my 5 for "TAMIL" PinmemberNagaraj Muthuchamy25-Feb-09 23:04 
GeneralA very Goood Article PinmemberMember 448984518-Dec-08 19:04 
GeneralGood Article PinmemberGanesan Sankaran16-Oct-07 2:40 
Generalgood example Pinmembercode_proj_18-May-07 15:40 
QuestionNice but, now what? Pinmemberroot@ccess7-Apr-07 0:27 

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 | Mobile
Web03 | 2.8.140827.1 | Last Updated 6 Apr 2007
Article Copyright 2007 by Saleth Prakash
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid