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.
Though 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, rather than having a single product description property that stores the description of a product in a single, default language, the schema can be extended to contain multiple description properties, one for each language that is supported.
For example, instead of having a short_description property, you could define three description properties, as follows: short_description_en for the English version, short_description_fr for the French version, and short_description_nl for the Dutch version. Then, based on the language choice of the user, your Active Server Page (ASP) code can dynamically request the appropriate description value to display.
For more information about changing the product catalog schema, see Changing Catalog Schema.
- 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 below:
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 the version of the string in a different language.
An instance of the MessageManager object is typically created and loaded with messages in the file Global.asa. 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 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 occurs.
- 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. The recommended technique is similar to that used for supporting multiple languages in the Product Catalog System.
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.
All rights reserved.