Click here to Skip to main content
14,874,239 members
Articles / Web Development / ASP.NET
Posted 18 Jul 2005


69 bookmarked

Satellite Assembly - Multi Languages

Rate me:
Please Sign up or sign in to vote.
4.35/5 (20 votes)
18 Jul 20053 min read
Creating a multi language ASP.NET site using Satellite Assemblies.

Image 1


As a professional developer, your clients might ask you to develop a website in which users can choose the language they want the site to be in. Somehow, this scenario can be done by developing several pages with several languages. Finally, you can satisfy the clients' requirements. However, it takes you a very long time, and it also wastes your money. There is a faster way to accomplish the requirement. Let's enjoy!

Using the code

First of all, we will take a look at the way a Satellite Assembly works. We won't make several pages in several languages. There is only one project with several resource files to save the translated strings. Let's do an example!

Create a new project in Microsoft Visual Studio .NET 2003. In the default web form, we start developing this project.

Notice: For the elements whose text you want to be displayed in many languages, you have to set the id and runat attributes. By default, the server-side controls have these attributes, but you have to add them to HTML elements.

For instance, if your site has the HTML code like this:

   <form id="Form1" method="post" runat="server">
      <p><b>Welcome to the Satellite Assembly...</b></p>
      <b>Select your language:</b>
         id="drpLanguages" runat="server"></asp:DropDownList>
        <asp:Button id="btnLanguages" runat="server" Text="Button"></asp:Button>
      <P> <STRONG>Thang Q. Tran</STRONG></P>
      <P>.NET Developer</P>
      <P><STRONG><a href="">Xtreme 

But when you want to develop with Satellite Assemblies, you have to add id and runat attributes to the HTML elements which you want to display in many languages. Then, the HTML code will be:

   <form id="Form1" method="post" runat="server">
      <p id = "p1" runat = "server"><b>Welcome to the 
                      Satellite Assembly...</b></p>
      <b id = "p2" runat = "server">Select your language:</b> 
      <asp:DropDownList id="drpLanguages" runat="server"></asp:DropDownList>
      <asp:Button id="btnLanguages" runat="server" Text="Button"></asp:Button></P>
      <P> <STRONG>Thang Q. Tran</STRONG></P>
      <P>.NET Developer</P>
      <P><STRONG><a href="">Xtreme 

Now, the user interface is okay! Let's make the resource files!

Create a fallback resource file containing the default strings to display in the user interface if the user's culture is not specified or not recognized. Name the fallback resource file <filename>.resx. For example: strings.resx.

Then, we create resource files containing the translated strings to display for each general language that your web application supports. Name the translated resource files <filename>.<languagecode>.resx. For example:

To create the fallback, from Project menu, choose Add > Add New Item and choose Assembly Resource File from the list of templates. Name it string.resx. And edit the file as you can like in the picture below:.

Image 2

The fallback resource file is done now. Let's create other resource files for other languages, in this case, German and Vietnamese.

This is the content of the file string.en-US.resx for English:

Image 3

And this is the content of the file for German:

Image 4

Finally, this is the file for Vietnamese.

Image 5

Now, we are going to start to write some code for it. First, we have to Import some namespaces:

Imports System.Resources
Imports System.Globalization
Imports System.Threading

Add the following code at the class level of the Web form to load the resources into the ResourceManager object:

Protected gStrings As New _
  ResourceManager("SatelliteAssemblies.string", _


The bold text in the previous code is the name of the assembly.

This is the code for the Page_Load event:

Private Sub Page_Load(ByVal sender As System.Object, _
         ByVal e As System.EventArgs) Handles MyBase.Load
    'Put user code to initialize the page here

    If Not Page.IsPostBack Then
        drpLanguages.Items.Add(New _
          System.Web.UI.WebControls.ListItem("English", "en-US"))
        drpLanguages.Items.Add(New _
          System.Web.UI.WebControls.ListItem("Deutsch", "de-DE"))
        drpLanguages.Items.Add(New _
          System.Web.UI.WebControls.ListItem("Ti&#7871;ng Vi&#7879;t", "vi-VN"))

        Dim sLang As String = "en-US"
    End If
End Sub

In the Page_Load event, we call a method SetCulture() with one parameter:

Private Sub SetCulture(ByVal sLang As String)
        Thread.CurrentThread.CurrentUICulture = New CultureInfo(sLang)
        Thread.CurrentThread.CurrentCulture = _
        p1.InnerHtml = gStrings.GetString("p1")
        p2.InnerHtml = gStrings.GetString("p2")
        btnLanguages.Text = gStrings.GetString("btnLanguages")
End Sub

In this method, we receive one parameter as the code for the language. Then we set the CurrentCulture to this language. When the button is clicked, we get the value of the selected item from the drop down list and call the method SetCulture() with the parameter as this value.

Private Sub btnLanguages_Click(ByVal sender As System.Object, _
          ByVal e As System.EventArgs) Handles btnLanguages.Click
    Dim sLang As String = drpLanguages.SelectedItem.Value
End Sub

Now, everything is done! Why don't you test the project? Try to change the value in the drop down list and click the button to change the language. Does it work well?

You can develop a website with more and more languages with less time by using Satellite Assemblies! The only thing you have to do is create more resource files.


  • Developing Web Applications with Microsoft Visual Basic .NET and Microsoft Visual C# .NET (Exams 70-305 and 70-315) e-Book


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


About the Author

Thang T.
Software Developer (Senior)
Vietnam Vietnam
I've been working as a freelance iOS developer since the invention of the original iPhone. After numbers of projects, I gain more and more experience, get familiar with popular 3rd-party libraries which can save time and cost in the development.

With the experiences gained by working on projects, I proudly offer consultancy service which supports my customers to (1) get the best way to develop their apps; (2) start up iOS apps business professionally & effectively.

My day starts with the practices Japanese traditional Martial Arts: Kendo ( & Iaido ( Therefore, I always work with Samurai Spirit in the entire day, no FEAR and willing to take CHALLENGES!

If you need to get your iOS games or apps done, I'm available at oDesk!

Comments and Discussions

GeneralRe: How to Generate New Resource Files from Other Langugaes Pin
Thang T.31-Jul-05 2:21
MemberThang T.31-Jul-05 2:21 

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.