Localizing Web Site Text

On Web sites that support multiple languages, rendered pages must be capable of displaying text in the language chosen by the user. You must first decide whether you will build and maintain parallel Web sites in different languages, or whether you will build a single Web site that dynamically builds each page in the appropriate language.

Although the parallel Web site approach offers better performance due to its more static nature, the maintenance burden of keeping multiple Web sites synchronized has made this approach unpopular.

Commerce Server includes features to make the dynamic approach easier to develop. These features include:

  • Product Catalog System. The extensible nature of the Product Catalog System provides a convenient mechanism for storing multiple language information for each product in the catalog. For example, you can create multilingual properties for product descriptions, and then display the appropriate description based on the preferred language of a user. For more information about the Product Catalog System, see Product Catalog System.

  • MessageManager Object. This object serves as a repository for text strings used on a Web site. It includes a mechanism for separating the symbolic name of the string from the particular language translation of the string. For example, you could output the string "Weekly Specials" in English using the GetMessage method of the MessageManager object, as shown in the following code example:

    Dim sLangChoice
    sLangChoice = "en"
    <%= oMessageManager.GetMessage("Weekly_Specials", sLangChoice)%>
    

    By changing the way in which the sLangChoice parameter is initialized, the same line of code could be used to display a version of the string in a different language.

    An instance of the MessageManager object is typically created and loaded with messages in the Global.asa file. A reference to this object is then placed in the intrinsic Application object so that all pages in the Web site have easy access to the stored messages. If multiple languages are being used, the initialization code in the Global.asa file will load the MessageManager object with multiple sets of messages, where each set corresponds to one of the languages being supported.

    If you provide a set of localized messages for a particular language, it is important that you provide a translated version of all corresponding text. If you attempt to call the GetMessage method of the MessageManager object and pass a string name and language for which no string exists, a run-time error will occur.

    All of the ASP sitelets provided in the SDK use the MessageManager object to display site text in the language established in the user profile.

    For more information about using the MessageManager object, see MessageManager Object.

  • CacheManager Object. This object can serve as a high-performance repository for strings or other data that are used frequently. Since retrieval from a CacheManager object is dependent upon a single key string, and not a combination of a key string and a language string as is the case for the MessageManager object, the choice of language must be embedded within the key string itself.

    For example, multiple language versions of the same string in English, French, and Dutch could be stored in a CacheManager object, with the key strings for each ending in "_en", "_fr", and "_nl", respectively. The key string would be built dynamically, altering the final component of the string based on the language choice of the user.

    For more information about using the CacheManager object, see CacheManager Object and Core Objects.

  • .NET support for localization of static text

    ASP.NET handles the internationalization of static text differently from ASP. With ASP.NET, the localized resources are separated into a resource file (.resx) that can be embedded in an assembly or a satellite assembly on a per culture basis.

    The .NET ResourceManager class is used to retrieve the appropriate resources from the .resx file based on culture settings. There is a built-in fall-back mechanism for when resources for a culture are missing. For more information about the .NET Resource Manager, search on "Resource Manager" in the .NET Framework SDK located at https://go.microsoft.com/fwlink/?LinkId=6680.

    For example, if you want to support French Canadian (fr-CA) and French France (fr-FR) cultures, you can do so with one set of French resources marked as simply "fr". When the site user selects the fr-CA culture, the .NET globalization namespace methods provide a way to appropriately display currencies, and dates for the fr-CA culture. In this case, the Resource Manager will look for resources marked as fr-CA, will not find any, and will then automatically look for an existing country/region neutral culture for "fr". The Resource Manager will find the "fr" resources, and the strings will be loaded.

    Ee824359.note(en-US,CS.20).gifNotes

    • If the "fr" resource did not exist. the Resource Manager would fall back to the default resources.
    • A tool, called the Resource File Generator (resgen), is provided to migrate from rc.xml to resx. Resgen converts .txt files and .resx (XML-based resource format) files to common language run-time binary resources files that can be embedded in a run-time binary executable, or compiled into satellite assemblies.

Copyright © 2005 Microsoft Corporation.
All rights reserved.