If you want to internationalize your product catalog, you can extend the Commerce repository to support translated versions of some properties. This section outlines the internationalization strategy that is implemented as part of the Oracle ATG Web Commerce Reference Store. This “best practice” offers the following benefits over other approaches:
Applications can switch between international and non-international modes without requiring any JSP page changes. The same property names are used in the JSP page code and each repository derives the appropriate language as necessary.
No database schema changes are required to add additional languages.
To extend your repository to include internationalized values, follow these steps:
Decide which properties of which item types you want to translate. This example uses properties of the SKU item type, but you may need to translate product, category, and even catalog properties, depending on your catalog structure.
For each item type you are internationalizing, add new properties corresponding to that item type’s translatable properties.
For example, you want to provide internationalized versions of four
SKU
properties:displayName
,description
,size
, andcolor
. You would add four new properties (displayNameDefault
,descriptionDefault
,sizeDefault
, andcolorDefault
) to theSKU
item descriptor.The new properties refer to the original properties’ database columns and represent the default text for the properties (thereby allowing us to redefine the original properties as derived properties).
These four properties refer to the
display_name
,description
,sku_size
, andcolor
columns, where default-language text for the content are stored.Add another property to the item type. This property (with a name such as
translations
) is a map whose key is alocale
and whose value is an item of typebaseType
Translation
, described below. Note that thelocale
key does not have to be a fully qualified locale.Define a set of helper item types for all existing item types that have translatable properties. Our example uses the naming convention
baseType
Translation
, wherebaseType
refers to an existing item type; for example, create askuTranslation
item type to correspond with thesku
item type, aproductTranslation
item type for theproduct
item type, and so on.baseType
Translation
items function as containers for locale-specific content. As such, eachbaseType
Translation
item type has properties that correspond to the translatable properties of its base item type. In our example, we have selected four SKU properties for translation (displayName
,description
,size
, andcolor
).skuTranslation
item also has four properties fordisplayname
,description
,size
, andcolor
. EachbaseType
Translation
item type has its own table in the database, where each row represents a singlebasetype
Translation
item with a unique ID. For example, thecbp_sku_xlate
table contains all theskuTranslation
items, thecbp_prd_xlate
table contains all theproductTranslation
items, and so on.
Every base item (SKU, product, category) is tied, through its translations
property, to one or more baseType
Translation
items (one for each locale, with the exception of the default locale). The following example shows three sku
items and six corresponding skuTranslation
items which contain translated content for two locales, French and German.
To create the relationships that connect a base item to its baseType
Translation
items, change the definitions of the translatable properties in the existing item types. The new definitions should specify that each translatable property is a derived property whose value is determined as follows:
Use the current locale to look up a corresponding
baseType
Translation
item in thetranslations
property map. The property derivation attempts to find a best match. First, it searches thelocale
keys for a match on the entire locale with a variant, then it searches for a match on the locale without a variant, and finally it searches on just the language code.If a
baseType
Translation
item exists for the current locale, use its value for the property.If a
baseType
Translation
item doesn’t exist for the current locale, or its value for the property is null, use thetranslatableProperty
Default
value instead.
The Oracle ATG Web Commerce Reference Store code uses the atg.repository.dp.LanguageTranslation
class to implement the derivation.
The following example shows how Commerce Reference Store derives the sku.displayName
property for a store that has English (default), German, and French translations:
giftListShop.jsp
requests thesku.displayName
property for a SKU and determines the locale, which in this example isDE_de
.The catalog repository finds the corresponding
skuTranslation
item using thetranslations
property map. Based on the locale, the repository determines that it should reference the GermanskuTranslation
item.The catalog repository returns the
displayName
property from the GermanskuTranslation
item.If no
skuTranslation
item exists for the locale, it returns the value fromdisplayNameDefault
.