Click here to Skip to main content
15,886,199 members
Articles / Programming Languages / C#

Create satellite assemblies with ResX Builder

Rate me:
Please Sign up or sign in to vote.
3.10/5 (9 votes)
13 Nov 2010CPOL3 min read 30.1K   684   13   6
How to create satellite assemblies with ResX Builder.

Introduction

Localization in Visual Studio is very good, and whilst I found it suitable for almost every situation, there is one issue that can cause a lot of grief; how does one deploy new satellite assemblies when an application has already been built? For many small projects, this is not an issue, and the developer simply deploys a new version. However, this is not always an easy choice to make. Wouldn't it be wonderful to create a satellite assembly and upload it to your application without having to rebuild? Well, you can! Let's start seeing how...

Traditional method: If you have the time and energy to work it out, you will come to use resgen.exe and al.exe, two tools included with the Visual Studio installation. Resgen.exe will take a RESX file and spit out a .resources file. Then, you take this, and with a load of different (and tricky syntax) commands, you will end up having written something like this:

"C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bin\resgen.exe" 
    "HelloResX.ja-JP.resx" "ResXTest.HelloResX.ja-JP.resources"

"C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bin\al.exe" /t:lib 
   /out:"ja-JP\ResXTest.resources.dll" /culture:ja-JP 
   /embed:"ResXTest.HelloResX.ja-JP.resources"

It may look easy, but I tell you... it can cause some serious grief at times. Right, so to minimize on grief, I have written a nice GUI utility that I hope some of you will find useful. Let's get into explaining ResXBuilder then...

Simplifying the process with ResX Builder

All you need to do is fire up the tool, enter some info, and click Build, then voila; your new satellite assembly is ready to deploy.

Main.PNG

As you can see from the screenshot above, the main area is a grid, and basically what this is for is editing the values of an existing .resx file. For example, say you have a default .resx file called HelloResX.resx; you tell the tool where to find the template file (your default .resx file) and then click Load. This will bring up all the name/value pairs in a grid that you can edit. Once you're done translating, simply select a culture and specify the resource namespace and project name, then click Build. That's it; you're ready to deploy!

A demo app

In the attached source code, you will find a demo project. In there, you will see the following simple code:

C#
static void Main(string[] args)
{
   List<string> cultures = new List<string>();
   cultures.Add("en-US");
   cultures.Add("zh-CHS");
   cultures.Add("ja-JP");
   cultures.Add("vi-VN");
   cultures.Add("ru-RU");

   cultures.ForEach(HiBye);
   Console.ReadLine();
}

private static void HiBye(string cultureCode)
{
   HelloResX.Culture = CultureInfo.GetCultureInfo(cultureCode);
   Console.WriteLine("Culture: {0}", cultureCode);
   Console.WriteLine("Hello: {0}", HelloResX.Hello);
   Console.WriteLine("Goodbye: {0}", HelloResX.Goodbye);
   Console.WriteLine();
}

Basically, I only have one resources file: HelloResX.resx, and because it is strongly typed, we can call the properties on it directly. By default, it will use the current culture, but if you change the Culture property as in the above code, it will try to locate the required satellite assembly from the bin folder. What I am doing in the above code is setting the culture 5 times for 5 different cultures and writing the name/value pairs to the Console. Of course, in a real world app, you won't know what cultures to load, and you would get the user to select the culture they want to use from a dropdown or something, and then try load it from there. The images below show before and after I added the satellite assemblies to the bin folder.

TestBefore.PNG

Before

TestAfter.PNG

After

Conclusion

Satellite assemblies; very useful... command line tools to generate them; nasty... GUI tools to handle the issue; makes generating satellite assemblies quick and easy. Enjoy!

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) Freelancer
Australia Australia
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionWhy 4 stars Pin
Stefan Vasiljevic28-Oct-14 4:00
Stefan Vasiljevic28-Oct-14 4:00 
Bug[My vote of 1] Vote of 1 Pin
User 466676224-Dec-13 12:08
User 466676224-Dec-13 12:08 
The Programm is pretty buggy and not really worth the hassle in the current state.
GeneralMy vote of 5 Pin
dheerajv25-Jul-12 16:44
dheerajv25-Jul-12 16:44 
QuestionMBG not found--code is not working Pin
MrNilesh14-Dec-11 23:54
MrNilesh14-Dec-11 23:54 
AnswerRe: MBG not found--code is not working Pin
De Nardis Andrea24-Mar-12 7:34
De Nardis Andrea24-Mar-12 7:34 
GeneralMy vote of 1 Pin
bcraun18-Mar-11 10:03
bcraun18-Mar-11 10:03 

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.