Using Satellite Assemblies for Multi-Language Programming
A generally accepted programming practice is to use constants for content like text strings. By taking this practice one step further with a modest amount of work you can prepare your applications for customers that speak other languages.
In this article I will demonstrate how to build an external resource file for your application's text and build additional files for multi-language support. After reading this article you will know how to build a resource file, compile the resource file using the resgen.exe utility and embed the resource file in a satellite assembly using the al.exe (assembly linker) utility. Finally, we will wrap up with a practical approach that developers can employ to simplify testing resource assemblies before throwing them over the wall to testing teams or customers.
Externalizing Text Content
It is easy to use the Visual Studio .NET IDE and the Properties window to add text content to your application's controls. Other content, like that displayed in a MessageBox, Console, or Web page, is often embedded amongst the lines of code or as constants. Externalizing this text content only requires a bit of additional work and prepares your application for globalization.
Creating a Resource Text File
A resource file can be started by adding a text file to your project or by using any text editor like Notepad. Name the text file the same name as your target assembly name with a .txt extension. Use a line of text preceded with a semi-colon if you want to add a comment to your resource source file and add the text in name = value pairs. By convention the names use an RES_ prefix and all uppercase words separated by underscores—similar to the popular constant naming convention. Hence, if you had a constant for a database connection error one might write the resource string as follows:
RES_DATABASE_CONNECTION_ERROR = Unable to connect to database
Each of the name and value pairs must be on a single line in the text file.
Compiling a Resource File
After each of the content strings we are ready to compile the text file into a resources file using the resgen.exe (resource generator) utility. If you click on the Start|All Programs|Microsoft Visual Studio .NET 2003|Visual Studio .NET Tools|Visual Studio .NET 2003 Command Prompt then the necessary environment variables, including paths to the .NET SDK utilities, will be properly configured.
To compile the text file into a resources file we need to run the resource generator passing the name of the input text file and optionally the resources output file. For example, if our target assembly is myapp.exe then my input file should by myapp.txt and the output file should be myapp.resources, and the resource generator command line would be
resgen myapp.txt myapp.resources
After compiling the resource text file into a resources file we can add the resources file to the application. This resource will be embedded into the target assembly and will represent the default resource and consequently default language of the application.
Page 1 of 3