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 Villagois table glasses, and receive a decanter and a cork screw 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 WebSphere Commerce Developer.
  2. Create a new package for the properties file:
    1. In the Enterprise Explorer view, navigate to LOBTools > JavaResources: src.
    2. Right-click the src folder, and then click New > Package.
    3. In the New Java Package window, create a new properties package named com.mycompany.commerce.promotion.client.lobtools.properties.
    4. Click Finish.
  3. In the new properties package, create a new file:
    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.
  4. 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.lzx  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 $100 or more on Villagois table glasses, and receive a decanter and a cork screw 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   
    
    
  5. Save and close the file.
  6. Create a new directory structure for your custom code:
    1. In the Enterprise Explorer view, navigate to LOBTools > WebContent > WEB-INF > src > lzx.
    2. Right-click the lzx folder and click New > Folder.

      View
    3. In the Folder name field, type mycompany.
      All of your customized OpenLaszlo code should be put under this folder.
    4. Click Finish.
    5. Complete one of the following steps:
      • WebSphere Commerce Version 7.0.0.0Feature Pack 1Create the remainder of the directory structure you need for this tutorial, which is mycompany/promotion/objectDefinitions/elements. Your directory structure should now look like this:

        Directory structure for custom code
      • Introduced in Feature Pack 3Feature Pack 2Create the promotion directory. Your directory structure should now look like this:

        Directory structure for custom code
  7. The new text strings added in the properties file cannot be used by OpenLaszlo classes or Management Center definitions directly. Register the properties with the new resource bundles:
    1. In the Enterprise Explorer view, navigate to LOBTools > WebContent > WEB-INF > src > lzx > mycompany > promotion.
    2. Right-click the promotion directory; then 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 PromotionResourceBundle.lzx.
    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.lzx:
      
      <library>
           <!---        
           Resource bundle for the customized Promotion component and all the resource keys used are defined here. A global instance of this class is instantiated with the id <code>extPromotionResources</code>.
           -->
           <class name="extPromotionResourceBundle" extends="wcfResourceBundle"
                baseName="com.mycompany.commerce.promotion.client.lobtools.properties.PromotionLOB">
                <wcfResourceBundleKey name="promotion_type_ProductLevelFreeGift" /> 
                <wcfResourceBundleKey name="promotion_type_description_ProductLevelFreeGift" /> 
                <wcfResourceBundleKey name="promotion_Minimum_purchase_TotalPrice" /> 
                <wcfResourceBundleKey name="promotion_Free_gift_qty" />
           </class>
           <extPromotionResourceBundle id="extPromotionResources"/>
      </library>         
      
      WebSphere Commerce Version 7.0.0.0Feature Pack 1To refer to the resource bundle from other OpenLaszlo classes, use the ID in the resource bundle class. In this example, the ID is extPromotionResources. Therefore, to use the resource "promotion_type_ProductLevelFreeGift" in the OpenLaszlo source, the reference would look like this:
      ${extPromotionResources.promotion_type_ProductLevelFreeGift.string}
      Introduced in Feature Pack 3Feature Pack 2To 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_type_ProductLevelFreeGift}
    8. Save and close the file.
  8. Register the new resource bundle class in the promotion extensions library:
    1. Open the file at this path:

      LOBTools/WebContent/WEB-INF/src/lzx/commerce/promotion/PromotionExtensionsLibrary.lzx

      This library is used to register all custom files related to the promotions component. Include your file in the library to make it available to all other OpenLaszlo classes.
    2. Add the following include statement within the <library> element:
      <include href="../../mycompany/promotion/PromotionResourceBundle.lzx"/>
    3. Save the file, but leave it open so that your do not have to reopen it later in this tutorial to register additional custom files.
  9. Right-click the LOBTools project; then click Build OpenLaszlo Project on the context menu.
  10. Restart the WebSphere Commerce test server.
    The properties that you defined are available.

Results

In this lesson, you completed the new properties file and resource bundles definition. In the next lesson, you will define a new OpenLaszlo object definition class to represent the new purchase condition promotion element.