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.
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:
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.
Before
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!