Use Resource Files for Localization

You can prepare dynamic menus for other cultures by using resource files. Microsoft describes three steps to localizing an application: globalization, localizability, and localization. The names are confusing, but steps they describe are valid: Isolate strings you'll display to users, test that all strings are isolated, and create the localized strings in each target language. However, even though separating the testing from creating localized strings is a noble idea, you'll probably be testing as you create your first localized version, unless you use a localization tool. Extending to additional cultures is easier if you plan the first alternate culture as a separate step.

Preparing for translated strings is one of the many aspects of localization. Resource files are the easiest way to isolate strings. You can create resource files in the RESX format within VS.NET by selecting an Assembly Resource File. Even though RESX files are XML, you can edit them comfortably with the default editor. (This doesn't work for objects, but it works well for strings.) Supply the name, value, and an optional comment. Leave the type and mime type empty for strings.

VS.NET compiles the RESX files into a standard resource file, which is in binary format. The naming at this point is effective but might be surprising. VS.NET prefixes the name with the project namespace and changes the extension to RESOURCES. The DynamicMenus.resx file within the sample code for this article is embedded in the assembly as DynamicSupport.DynamicMenus.resources.

The easiest way to access these resources is through a ResourceManager. The most important aspect of ResourceManager objects is to handle satellite assemblies transparently with details for each supported culture. You lay an important part of the groundwork for later localization by using resource managers. You can create ResourceManagers easily:

Dim rm As New _
	System.Resources.ResourceManager( _
	resName, assembly)

Once you have the resource manager, you can use the GetString and GetObject methods to retrieve resource values.