17.3. Using Global Resources and Overriding Currency Formatting

Problem

You want to reuse resources throughout your international application, and you must always display currency with the U.S. dollar symbol, but all other text must follow the language setting in the browser.

Solution

Create a root global resource for your application, add the required items, explicitly set the values of static text in the .aspx files, set the culture and uiCulture attributes of the <globalization> element in web.config to auto, and set the values for dynamic controls in the code-behind class overriding the UI Culture when setting currency values.

Create a global resource file as follows:

  • Create an App_GlobalResources folder in the root of your application.

  • Add a resource file to the App_GlobalResources folder.

  • Edit the resource file to include the required items.

  • Duplicate the root resource file for each language and culture to be supported by your application, setting the values to the resource items as appropriate for the language.

In the .aspx files of your application:

  • Explicitly set the values for all controls that display static text.

Set the culture and uiCulture attributes of the <globalization> element in web.config to auto;

	<globalization culture="auto" uiCulture="auto" />

In the code-behind class for each page that needs to support multiple languages, use the .NET language of your choice to:

  • Set the values of controls used for date.

  • Set the values of controls used for currency overriding the UI ...

Get ASP.NET 2.0 Cookbook, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.