Creating new resource bundles for custom text strings

In this lesson, you create a new properties file and resource bundle to define the custom text strings to display on the Management Center user interface for your customized widgets. In the Management Center, all text labels and images displayed in the user interface must be defined as properties and registered in a resource bundles file.

About this task

A properties file is a resource bundle that contains translatable text that displays in the user interface. Resource bundles contain locale-specific objects. By using resource bundle files, the text can be easily translated into different languages. In the previous lesson, you planned the user interface you need to support your new promotion, and you determined that you need to include four new text strings:
Text string Description Resource key
"Minimum Purchase on base catalog entries ($)" The label for the total price threshold for the purchase condition promotion_Minimum_purchase_TotalPrice
"Quantity for free" The label for the gift quantity for the reward promotion_Free_gift_qty
"Spend $ on catalog entry X, get catalog entry Y free" The name of the new promotion type that appears in the Promotion Type Selector window promotion_type_ProductLevelFreeGift
"Purchase condition: Order contains a specified amount spent on a catalog entry.

Reward: One or more free gifts.

Example: "Spend $100 or more on KitcheCraft Chef Line Knife Set, and receive a Vienna glass free!"

The description of the new promotion type that appears in the Promotion Type Selector window promotion_type_description_ProductLevelFreeGift
You can reuse all other text strings from existing promotion types.

Procedure

  1. Open HCL Commerce Developer.
  2. Create a new package for the properties file:
    1. In the Enterprise Explorer view, expand LOBTools > JavaResources > src.
    2. Right-click the src folder, and select New > Package.
    3. In the New Java Package window, create a properties package that is named com.mycompany.commerce.promotion.client.lobtools.properties.
    4. Click Finish.
  3. In the new properties package, create the properties files for your promotion type:
    1. Right-click the com.mycompany.commerce.promotion.client.lobtools.properties properties package.
    2. Click New > Other.
    3. In the Select a wizard window, expand the General folder and click File.
    4. Click Next.
    5. Name your new file PromotionLOB_en_US.properties.
    6. Click Finish to save the file.
      The file opens in the default XML editor.
    7. To define the new properties, copy and paste the following code into the PromotionLOB_en_US.properties file:
      
      #===========================================================================
      # Customized Promotion Properties
      #===========================================================================
      #Used in extProductLevelFreeGiftTemplate to define the new Promotion type name in the drop down list
      promotion_type_ProductLevelFreeGift=Spend $ on catalog entry X, get catalog entry Y free
      #Used in PromotionTypeTemplatePicker.xml  to define the promotion type description in the Promotion Type Selector window
      promotion_type_description_ProductLevelFreeGift=<b>Purchase condition:</b>Order contains a specified amount spent on a catalog entry.<br/><br/><b>Reward:</b> One or more free gifts.<br/><br/><b>Example:</b><ul><li>Spend $200 or more on KitchenCraft Chef Line Knife Set, and receive a Vienna Glass free!</li></ul>
      #Used in extProductLevelFreeGiftProperties and extProductLevelFreeGiftPurchaseConditionObjectDefinition to define the property label of the total price threshold
      promotion_Minimum_purchase_TotalPrice=Minimum Purchase on base catalog entries ($)
      #Used in extProGiftRewardGrid and extProductLevelFreeGiftPurchaseConditionObjectDefinition to define the property label of the gift quantity
      promotion_Free_gift_qty=Quantity for free   
      
    8. Save and close the file.
    9. Repeat this step to create the PromotionLOB.properties file.
  4. Create a new directory structure for your custom code:
    1. Expand LOBTools > WebContent > WEB-INF > src > xml.
    2. Right-click the xml folder and click New > Folder.
    3. In the Folder name field, type mycompany.
      All of your customized definition file code should be put under this folder.
    4. Click Finish.
    5. Create a directory that is named promotionwithin your new mycompany directory.
  5. The new text strings added in the properties file cannot be used by Management Center definitions directly. Register the properties with the new resource bundles:
    1. Expand LOBTools > WebContent > WEB-INF > src > xml > mycompany > promotion.
    2. Right-click the promotion directory; then click New > Other.
    3. Expand the General folder and click File.
    4. Click Next.
    5. Name your new file PromotionResourceBundle.xml.
    6. Click Finish to save the file.
      The file opens in the default XML editor.
    7. To define the new resource bundle class and create an instance of it, copy and paste the following code into the file PromotionResourceBundle.xml:
      <?xml version="1.0" encoding="UTF-8"?>
      <Definitions>
           <ResourceBundle baseName="com.mycompany.commerce.promotion.client.lobtools.properties.PromotionLOB" 
            definitionName="cmc/promotion/ExtPromotionResources" singletonDefinition="true"/>
      </Definitions>
      To refer to the resource bundle from the Management Center definitions, use the ID in the resource bundle class. In this example, the ID is extPromotionResources. Therefore, to use the resource "promotion_type_ProductLevelFreeGift" in a Management Center definition, the reference would look like this:
      ${ExtPromotionResources.promotion_Minimum_purchase_TotalPrice}
      You must also include a dependency that identifies your resource bundle.
      <dependency localName="ExtPromotionResources" moduleName="cmc/promotion/ExtPromotionResources"/>
    8. Save and close the file.

Results

In this lesson, you completed the new properties file and resource bundles definition. In the next lesson, you create the definition of the new purchase condition promotion element.