Click here to Skip to main content
15,888,968 members
Articles / Programming Languages / C#

Satellite Assembly Example in C# (Step by Step)

Rate me:
Please Sign up or sign in to vote.
4.43/5 (25 votes)
22 Apr 2012CPOL2 min read 146.5K   3.9K   43   19
Implement a satellite assembly in C#.

Introduction

This article is about how to understand and implement a satellite assembly.

Background

A satellite assembly is a .NET Framework assembly containing resources specific to a given language. Using satellite assemblies, you can place resources for different languages in different assemblies, and the correct assembly is loaded into memory only if the user selects to view the application in that language.

(Source: http://vb.net-informations.com/framework/satellite-assembly.htm)

Using the code

Here is the step by step procedure to create an application with a satellite assembly:

1.Create a new Windows project (say: TestApp).


2.Add a ComboBox (name it cmbLanguage) and two Labels (one label for “Select Language” and the other for Displaying the Result (name it lblMultiLangResult)) as shown below:

UI

1. Add three Resx files (string.en-US.resx, string.he.resx, and string.ar-sa.resx for English, Hindi, and Arabic, respectively). Note: For other language codes, visit: http://msdn.microsoft.com/en-us/library/ms533052(v=vs.85).aspx

2. In the resx files, enter the values shown below:

Enter Values

5. Next, open the code file (.cs file) and create the object for the resource manager at class level:

C++
System.Resources.ResourceManager rm = new System.Resources.ResourceManager("TestApp.string", Assembly.GetExecutingAssembly());
Here in the first parameter: TestApp is the name of your Windows Application and string is the name of the Resource file part before the language code. Second parameter is the Main Assembly for the resources (for this you have to add the namespace: using System.Reflection;).

6. Write the following function for the culture:

C++
private void ChangeCulture(string sLangCode)
{
    Thread.CurrentThread.CurrentUICulture = new CultureInfo(sLangCode);
    Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(sLangCode);
    lblMultiLangResult.Text = rm.GetString("lblResult");
}
For the above function to run, please add the following namespaces:
C++
using System.Threading; //For Threading
using System.Globalization; //For CultureInfo

7. On the ComboBox item change event, add the following code:

C++
private void cmbLanguage_SelectedIndexChanged(object sender, EventArgs e)
    {
        string sLangCode;
        if (cmbLanguage.SelectedIndex == 0)
        {
            sLangCode = "en-US";
            ChangeCulture(sLangCode);
        }
        else if (cmbLanguage.SelectedIndex == 1)
        {
            sLangCode = "he";
            ChangeCulture(sLangCode);
        }
        else if (cmbLanguage.SelectedIndex == 2)
        {
            sLangCode = "ar-sa";
            ChangeCulture(sLangCode);
        }
    }

8. On page load, add the following line of code:

C++
ChangeCulture("en-US");

9. Run the application and see the output as below:

output

Points of Interest

When you look at ApplicationFolder/bin/release (check bin/debug if you are running in debug mode), there are three folders containing the same name of the DLL but each for different culture. The correct one will load when the user selects one of them.

Satellite Assembly

License

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


Written By
Software Developer (Senior)
India India
Linkedin profile: http://www.linkedin.com/profile/view?id=241442098

Comments and Discussions

 
QuestionNice Article Pin
BlindCoder1072-Jan-18 20:20
BlindCoder1072-Jan-18 20:20 
AnswerRe: Nice Article Pin
Vipin_Arora26-Nov-18 16:46
Vipin_Arora26-Nov-18 16:46 
GeneralThanks a lot for posting this example Pin
chensike8911-Nov-15 10:09
chensike8911-Nov-15 10:09 
GeneralRe: Thanks a lot for posting this example Pin
Vipin_Arora21-Nov-15 1:25
Vipin_Arora21-Nov-15 1:25 
GeneralMy vote of 5 Pin
Ehsan Sajjad20-Oct-15 0:14
professionalEhsan Sajjad20-Oct-15 0:14 
QuestionCorrect Arabic word Pin
Mohammed Qutaty15-Feb-15 7:42
Mohammed Qutaty15-Feb-15 7:42 
AnswerRe: Correct Arabic word Pin
Vipin_Arora15-Feb-15 16:16
Vipin_Arora15-Feb-15 16:16 
GeneralMy vote of 5 Pin
Thomas ktg18-Mar-14 1:40
Thomas ktg18-Mar-14 1:40 
QuestionConcise and easy. Pin
Septimus Hedgehog12-Feb-14 5:32
Septimus Hedgehog12-Feb-14 5:32 
AnswerRe: Concise and easy. Pin
Vipin_Arora26-Nov-18 16:45
Vipin_Arora26-Nov-18 16:45 
GeneralNice article Pin
Birendra Singh19-Nov-13 23:27
Birendra Singh19-Nov-13 23:27 
GeneralRe: Nice article Pin
Vipin_Arora20-Nov-13 16:17
Vipin_Arora20-Nov-13 16:17 
QuestionVery Useful Pin
Vedangi2-Oct-13 22:39
Vedangi2-Oct-13 22:39 
AnswerRe: Very Useful Pin
Vipin_Arora4-Oct-13 23:13
Vipin_Arora4-Oct-13 23:13 
GeneralMy vote of 4 Pin
Er. Vikas Sangal12-Mar-13 20:27
Er. Vikas Sangal12-Mar-13 20:27 
GeneralRe: My vote of 4 Pin
Vipin_Arora26-Nov-18 16:44
Vipin_Arora26-Nov-18 16:44 
GeneralMy vote of 5 Pin
madver14-Feb-13 14:27
madver14-Feb-13 14:27 
GeneralRe: My vote of 5 Pin
Vipin_Arora26-Nov-18 16:43
Vipin_Arora26-Nov-18 16:43 
GeneralMy vote of 2 Pin
vinay8724-Aug-12 19:32
vinay8724-Aug-12 19:32 

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.