April 23, 2014
Hot Topics:
RSS RSS feed Download our iPhone app

Using Satellite Assemblies for Multi-Language Programming, Page 3

  • September 26, 2003
  • By Paul Kimmel, Paul Kimmel
  • Send Email »
  • More Articles »

Testing a Language Assembly

I'm a firm believer that developers should perform unit testing and get as many bugs out the code before it goes to testing. To that end we need to test our satellite assemblies. There are two good ways to test multi-language clients: one is to change the current culture information for the assembly and the second is to install software like VMWare or Virtual PC and set up a partition on your development machine with the language versions you'd like to test. For our purposes we'll change the culture information to see if the same code, without revision, properly loads the correct culture text when we change the current culture to de-DE.

An easy way to change the culture information is to import System.Threading and set the culture name to the names we'd like to test. In our simple Windows Forms application we can accomplish this by assigning a new CultureInfo object to Form Thread's CurrentUICulture property, as demonstrated:

Thread.CurrentThread.CurrentUICulture = _
  New CultureInfo("de-DE")

Re-run the sample application. Now when the statement requesting the RES_WHAT resource string is requested the application should automatically load the satellite assembly and the correct language version of the string. To verify this you can open the Debug|Windows|Modules window and see that the resource satellite is automatically resolved when the ResourceManager.GetString method is called.



Click here for larger image

Figure 2: The correct satellite resource assembly is loaded, as shown, when the culture information has changed and resources are requested.

Summary

Using resource files is a good way to separate content from the behavior of an application. It is possible to implement the application and let the language lawyers figure out the content. A greater benefit is that by externalizing resources and creating satellite assemblies the same body of code will load resources needed for each of the languages you'd like to support. Additionally, the satellite assemblies can be added and shipped over time as you elect to support a greater variety of languages.

In this article you learned that text values containing name and value pairs can be compiled and embedded into satellite assemblies using the resgen.exe and al.exe utilities. After the default resource and satellite assemblies are created, the correct content will be dynamically loaded by the ResourceManager class based on the culture information. When running in the current culture the default resources will be used, and without modifying your code, the correct satellite assembly—if you have created one for the specific culture—will be loaded when the application runs in the context of an alternate culture.

About the Author

Paul Kimmel is a software architect, writer, and columnist for codeguru.com. Look for his recent book Visual Basic .NET Power Coding from Addison-Wesley. Paul Kimmel is available to help design and build your .NET solutions and can be contacted at pkimmel@softconcepts.com .

# # #





Page 3 of 3



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Sitemap | Contact Us

Rocket Fuel