Click here to Skip to main content
Email Password   helpLost your password?

Introduction

Microsoft released the .NET Framework and common language runtime model, targeting high productivity in software development. Their goal was to create an enriched user experience with easy-to-use products. Satellite assembly comes into the picture when we develop an application that is localized to a specific culture. Throughout this article, we will explain the use and implementation details of satellite assembly.

However, in order to talk about localization, we must know about resource files. Resource files are nothing but a key and textual value collections specific to each language. Therefore we will have to create a resource file for each language that we plan to support. The .NET Framework classes will retrieve language-specific details from these multiple language resource files based on the chosen language context.

Resource File and Satellite Assembly

As we discussed earlier, resource files are essentially a collection of associations between key and textual values specific to a particular language. Resource files can be text, XML or binary resource files. Presumably, the resource file can be generated by language translators in either of the discussed file types. This can later converted using resgen.exe, which can convert a resource file from one format to another. Later, this file gets compiled and will become part of your application. This is called satellite assembly.

To create a resource file, you can highlight a project or a folder and add a new item of the type "assembly resource." This will create a resource file with the extension *.resx. It is also clear that you can have multiple resource files in your project. Once we fill the *.resx file with language-specific details, we then need to use resgen.exe to create a resource file. The below statement will help to achieve this same idea.

resgen fr-FR.resx SatelliteAssembly.fr-FR.resources
Screenshot - image001.jpg

The next step is to create a satellite assembly from the resource generated by the last command line execution. To create a satellite assembly, we can use an assembly linker, al.exe (see MSDN article), which is shipped along with the Visual Studio software kit.

al /t:lib /embed:SatelliteAssembly.fr-FR.resources
/culture:fr /out:SatelliteAssembly.fr-FR.resources.dll
Screenshot - image002.jpg

Repeat the above two command line expressions to create the satellite assembly for all required language support. So, at this stage we are done with the core part of localization. The next phase would be binding the language-specific details to the control object (in this example).

Resource Manager

The ResourceManager class looks up culture-specific resources, provides resource fallback when a localized resource does not exist, and supports resource serialization.

The enclosed example will be using the GetString method of ResourceManager, which can read the textual information from the resources for a particular culture. By default, this method returns the resource for the culture determined by the current cultural settings of the thread that made the call.

In the source code, we have a Windows Form object with combo box control. This combo box will populate all the available cultures.

Screenshot - image003.jpg
ResourceManager rm = null;
CultureInfo ci = Thread.CurrentThread.CurrentCulture;
if (comboBox1.Text == "German - Germany")
{
    rm = new ResourceManager("SatelliteAssembly.de-DE", 
        Assembly.GetExecutingAssembly());
    lblOne.Text = rm.GetString("StrMsgOne");
    lblTwo.Text = rm.GetString("StrMsgTwo");
}
Screenshot - image004.jpg
else if (comboBox1.Text == "French - France")
{
    rm = new ResourceManager("SatelliteAssembly.fr-FR", 
        Assembly.GetExecutingAssembly());
    lblOne.Text = rm.GetString("StrMsgOne");
    lblTwo.Text = rm.GetString("StrMsgTwo");
}
Screenshot - image005.jpg

Note: The code block enclosed here is just to demonstrate the GetString method of the ResourceManager class. You can download the source code and then fine-tune the logic or you can use the example.

History

You must Sign In to use this message board.
 
 
Per page   
 FirstPrevNext
GeneralMy vote of 1
anant.sinha
12:01 10 Feb '10  
poorly written
GeneralDoubled article
Przemyslaw Celej
13:12 29 Sep '07  
Hello,

There is already another article about localization in .NET:
http://www.codeproject.com/dotnet/Localization.asp

Regards
GeneralRe: Doubled article
sreejith ss nair
21:21 30 Sep '07  
It never intends to be a replica but a choice.;)
GeneralBefore now Earth was flat
gnk
16:56 27 Sep '07  
"Before now, no one ever really bothered to create language-specific information when dealing with localization" WTF

-- You're kidding, right?

gnk

GeneralRe: Before now Earth was flat
sreejith ss nair
21:20 30 Sep '07  
I respect your comment. And updated the same.


Last Updated 27 Sep 2007 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2010