To aid in internationalization, ATG Commerce includes a feature that allows you to specify alternate text for some catalog items using derived properties. You can add a derivation property to any property in the catalog, then specify alternatives to use in each catalog. For example, you could specify different display text to appear in different languages for the same catalog item.

The following example shows how to expand the displayName property to include English and German versions. As provided in ATG Commerce, displayName looks like this:

<item-descriptor name="sku"
  <table name="dcs_sku" type="primary" id-column="sku_id">
    <property name="displayName" column-name="display_name" data-type="string"/>
  </table>
</item-descriptor>

First, create two new properties, one for the English display name (reusing the column above) and one for the German display name (this requires a new table).

We start off with the name of the item descriptor containing the property:

<item-descriptor name="sku">

Remove the old definition of displayName. In order for the XML combination to work, do this inside the correct table tag:

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

To reuse the column name for the English display name (this way the English values do not need to be copied anywhere), define the English display name in the same table tag, then close the table:

  <property name="displayName_en" column-name="dislpay_name" data-type="string">
    <attribute name="locale" value="en"/>
  </property>
</table>

Notice there is an attribute called “locale” on this property. The derivation method uses this to determine the correct value.

Now define the German version. It looks similar to the English version above (with a different “locale” attribute). Define a new table for this:

<table name="dcs_sku_de" type="auxiliary" id-column="sku_id">
  <property name="displayName_de" column-name="display_name" data-type="string">
    <attribute name="locale" value="de"/>
  </property>
</table>

Next, define the derived property. Giving it the same name as the previously English property (“displayName”) means that JSP code that references this does not have to be rewritten:

<property name="displayName data-type="string">
  <derivation user-method="atg.commerce.util.FirstWithLocale">
    <expression>displayName_en</expression>
    <expression>displayName_de</expression>
  </derivation>
    <attribute name="derivationAttribute" value="locale"/>
    <attribute name="keyService" value="/atg/userprofiling/LocaleService"/>
    <attribute name="keySubProperty" value="locale"/>
    <attribute name="defaultKey" value="en"/>
</property>

The <derivation> tag uses a custom derivation method called FirstWithLocale, a subclass of FirstWithAttribute. It performs the following actions:

The locale is searched in a locale-specific way. For example, if locale=fr_FR_EURO, it first looks for a property where the locale attribute is fr_FR_EURO, then look for “fr_FR”, and finally look for “fr.”

There is also a defaultKey, which keyService uses if the if the value with the real key is null. In other words, if the real key is “de_DE” and we are looking for displayName, but displayName_de is null, then return displayName_en instead (assuming its locale is “en” and the defaultKey is “en” or “en_US”).

Using a defaultKey may slow performance. If no default key is defined, it is not used. If the default key is the same as the current key, there are no performance implications. In all other cases, there is an extra clause on all search terms.

The complete XML looks like this:

<item-descriptor name="sku">
   <table name="dcs_sku" type="primary" id-column="sku_id">
     <property name="displayName" xml-combine="remove"/>
     <property name="displayName_en" column-name="dislpay_name"
          data-type="string">
      <attribute name="locale" value="en"/>
    </property>
  </table>

  <table name="dcs_sku_de" type="auxiliary" id-column="sku_id">
    <property name="displayName_de" column-name="display_name" data-type="string">
       <attribute name="locale" value="de"/>
     </property>
  </table>

  <property name="displayName data-type="string">
    <derivation user-method="atg.commerce.util.FirstWithLocale">
      <expression>displayName_en</expression>
      <expression>displayName_de</expression>
    </derivation>
    <attribute name="keyService" value="/atg/userprofiling/LocaleService"/>
    <attribute name="defaultKey" value="en_US"/>
  </property>
   </item-descriptor>
 
loading table of contents...