Using Satellite Assemblies for Localized Resources

Problem
You want to know how to use satellite assemblies to hold the strings and other resources (images, sound files, etc.) that your program uses.

Solution
Mark satellite assemblies with the AssemblyCulture attribute.

Comments
Satellite assemblies should contain no code, and their names should include .resources. For example, MyUtil.resources.dll for an app with the main assembly called MyUtil.dll.

Code example

// Add the following entry to the AssemblyInfo.cs file.
[assembly: AssemblyCulture("fr-FR")]

// Code in the main app to retrieve the resources.
string resourcesFile = "TestAutomation.UiStrings";
ResourceManager resources = new ResourceManager(resourcesFile, Assembly.GetExecutingAssembly());
string message = resources.GetString("Message");

/* Here's an additional way to retrieve a resource for a specific culture:
** Pass a CultureInfo object to the GetString method of the ResourceManager class.
*/
CultureInfo frCi = new CultureInfo("es-ES");
string greetings = resources.GetString("Message", frCi);

// Apply the usage of French resources.
Thread.CurrentThread.CurrentUICulture = new CultureInfo("fr-FR");

4 thoughts on “Using Satellite Assemblies for Localized Resources

    • Jason Riley June 17, 2018 / 7:33 pm

      Thanks. I am glad you found it helpful. Good luck!

      Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s