Estimated lesson time 30 minutes How Satellite Assemblies Work

Web application projects use satellite assemblies to store the translated strings, graphics, and other culture-dependent aspects of an application' s user interface. To create the assemblies themselves, you use the Resource Manager. At run time, the Web application loads the translated strings into the Web form based on the current thread' s CurrentUICulture property, as shown in Figure 15-5.

Figure 15-5 Satellite assemblies at work To use satellite assemblies, follow these steps:

1. Set the id and runat attributes for all of the user-interface elements of your application that require translation. Server controls have these attributes by default, but you will need to add them to HTML elements such as heading, paragraph, and span so that you can load translated strings into those elements.

2. Create a fallback resource file containing the default strings to display in the user interface if the user' s culture is not specified or not recognized. Name the fallback resource file filename .resx. For example: strings.resx.

3. Create resource files containing the translated strings to display for each general language that your Web application supports. Name the translated resource files filename.languagecode .resx. For example: strings.es.resx.

4. Optionally, create resource files containing the translated strings to display for each specific culture that your Web application supports. Name the resource file filename.languagecode-regioncode .resx. For example: strings.ex-MX.resx.

5. Write code to load the resources for the Web form using the ResourceManager class.

6. Write code to detect the user' s culture and set the Thread class' s CurrentCulture and CurrentUICulture properties to match. The CurrentCulture property determines how ASP.NET formats dates, currency, and numbers; the CurrentUICulture property determines which satellite assembly is used when loading translated strings.

7. Write code to get strings from the resource files and display them in elements on the Web form.

The following sections describe these steps in more detail.

Was this article helpful?

0 0

Post a comment