Motorprise is designed to support two languages: English and German. The content of the site is available in these two languages. We achieved this localization by adding German attributes to the catalog.

We used derived properties and a derivation method called FirstWithLocale to accomplish this.

Let’s use category.displayName in the Motorprise catalog, <ATG10dir>/Motorprise/config/atg/commerce/catalog/custom/customCatalog.xml, as an example. This is the name of the category that displays on catalog pages, such as “Brakes” or “Tools.”

First, we removed the existing definition of displayName from the default catalog schema:

<table name="dcs_category" type="primary" id-column-name="category_id">
  <property name="displayName" xml-combine="remove" />

The remove command must be in the correct table tag; otherwise the definition of displayName is not properly removed. This command will override the DCS table.

Our reason for removing this is that we are going to replace this “generic” property and replace it with an English display name and a German display name.

Then, inside the same table tag, we created a definition for the English display name. We reused the same column in the same database; that way, we didn’t have to do any data migration. The English value for displayName is already in this column. We call this new property displayName_en and then use an attribute tag to assign it a locale with a value of en.

<property name="displayName_en" data-type="string" column-name=
   "display_name" required="true" queryable="true" category-
   resource="categoryPresentation" display-name-resource="displayName">
 <attribute name="propertySortPriority" value="-8" />
 <attribute name="locale" value="en" />
</property>

Note that we used the same category-resource and display-name-resource for displayName_en that we used for displayName. You will notice below that we also used the same ones for displayName_de.) The ATG Control Center is able to recognize when a property has a locale attribute. It appends this attribute to the end of the resource string. For example, if the resource string is “Display name” then the English version will be “Display name (en)”. The most important part of this property definition is the locale attribute. You could use a more specific value such as “en_US” if necessary. The derivation method, which is described below, recognizes either.

Now that we have an English display name, for Motorprise we also want a German display name.

First, we created a new table, dbc_category_de, in the database to store all German properties for a category (except the multi-value properties like keywords.)

Inside the new table tag we create the German display name, displayName_de:

<table name="dbc_category_de" type="auxiliary" id-column-name=
   "category_id">
   <property name="displayName_de" data-type="string" column-name=
      "display_name" queryable="true" category-resource=
      "categoryPresentation" display-name-resource="displayName">
      <attribute name="propertySortPriority" value="-8" />
      <attribute name="locale" value="de" />
  </property>
</table>

Now we have an English display name and a German display name. We want the correct language to be chosen based on the user’s locale when they enter the site. To do this, we recreate the displayName property and use the FirstWithLocale derivation method. (We used the same name so we wouldn’t need to make any changes to the JSPs.)

<property name="displayName" data-type="string" category-resource=
   "categoryPresentationDerived" writable="false" display-name-resource=
   "displayName" queryable="true">
  <derivation user-method="atg.commerce.dp.FirstWithLocale">
 <expression>displayName_en</expression>
 <expression>displayName_de</expression>
 </derivation>
 <attribute name="resourceBundle"
     value="atg.projects.b2bstore.CustomCatalogTemplateResources" />
 <attribute name="propertySortPriority" value="-8" />
 <attribute name="keyService" value="/atg/userprofiling/LocaleService" />
 <attribute name="defaultKey" value="en_US" />
 </property>

This property is not in a table tag since it is not stored in the database. The keyService is a Nucleus component that tells us the locale of the current user. The defaultKey is used if there is no value for the locale that is provided by the key service. For example, if the user’s locale were sn_ZW, he or she would see the English display name, since we have not defined a display name for Shona speakers in Zimbabwe. The derivation method will first look for the full locale (such as de_DE) returned by the key service. If it can’t find anything, it then looks for just the language part of the locale. This is why we can set the locale of displayName_de to de and it will still be used if locale is de_DE.

Here are the definitions of the German properties for “category”. Notice that everything except “keywords” is in one table.

<!-- create german versions in a separate table -->
<table name="dbc_category_de" type="auxiliary" id-column-name=
   "category_id">

  <property name="displayName_de" data-type="string" column-name=
   "display_name" queryable="true" category-resource=
   "categoryPresentation" display-name-resource="displayName">
    <attribute name="propertySortPriority" value="-8"/>
    <attribute name="locale" value="de"/>
  </property>

  <property name="description_de" data-type="string" column-name=
     "description" queryable="true" category-resource=
     "categoryPresentation" display-name-resource="description">
    <attribute name="propertySortPriority" value="-7"/>
    <attribute name="locale" value="de"/>
  </property>

  <property name="longDescription_de" data-type="string" column-
     name="long_description" queryable="true" category-resource=
     "categoryPresentation" display-name-resource="longDescription">
    <attribute name="propertySortPriority" value="-6"/>
    <attribute name="locale" value="de"/>
  </property>

  <property name="template_de" item-type="media" column-name="template_id"
     queryable="true" category-resource="categoryPresentation"
     display-name-resource="template">
    <attribute name="propertySortPriority" value="-5"/>
    <attribute name="locale" value="de"/>
  </property>

</table>

<!-- create german keywords -->
<table name="dbc_cat_key_de" type="multi" id-column-name="category_id"
   multi-column-name="sequence_num">

  <property name="keywords_de" data-type="list" component-data-type=
     "string" column-name="keyword" category-resource=
     "categoryPresentation" display-name-resource="keywords">
     <attribute name="propertySortPriority" value="-4"/>
     <attribute name="locale" value="de"/>
  </property>
</table>

Copyright © 1997, 2012 Oracle and/or its affiliates. All rights reserved. Legal Notices