Internationalize LOV using switcher

Environment (JDeveloper, ADF BC)

Everybody knows how to internationalize his application at run time, for those who don’t know how to do this, they can check this document. However this can be done for labels, headers text,static LOV,…etc. The question is how can we internationalize model driven LOV or dynamic LOV, this example will explain one method to do this.

Use Case: our application supports two locales Arabic (ar) and English (en), and the user has the flexibility to change his locale at run time. In our application we have a registration form page which has a Bank attribute, this form based on RegDetails view, the Bank attribute will be populated from model drivel LOV, the lookup view that populate the Bank field has this structure in database.

( id     number(10),
arabic_name    varchar2(50),
english_name varchar2(50) ,

So when the user select Arabic locale at run time, arabic_name filed should be the display value in the Bank attribute in our form, and when the user change to English locale, english_name filed should be the display value in the Bank attribute in our form.

How to implement this use case:

Fortunately ADF BC allows us to define more than one LOV for a single attribute, and switch between them as your case need. The following steps show how can we implement this, supposed that our BC has been created in advance:

  1. Open RegDetails entity object, to add a transient attribute called userLocale. This attribute will hold two values ar (for Arabic loacle) and en (for English locale), and this attribute is set at run time.
  2. Open RegDetails view object, and add the previous attribute to your view object.
  3. Now we need to define Bank LOV, open RegDetails view, then expand the attributes and select the Bank attribute.  once you select the Bank attribute you will see List of values: Bank section, click the green plus sign to add a new LOV. The Create list of value window will be shown on your screen.
  4. Give a meaningful name for your LOV, select your data source or add a new one if you don’t have, select your List attribute as shown below.

    LOV arabic bank name

  5. In the same window, click the UI Hints tab, and from the available area select ArabicName and shuttle it the to selected area as show below.Press OK to close the window.

    LOV arabic bank name

  6. Repeat steps 3-5, to create another LOV, give it en_LOV_Bank name, and in step 5 select EnglishName instead of ArabicName as the display value.
  7. In RegDetails view add a new transient attribute BankLovSwitcher, The value of this attribute should contain the LOVs name which are created in the previous steps.
  8. Select your BankLovSwitcher attribute, and click edit (pencil symbol) to open Edit Attribute: BankLovSwitcher window. In the Value Typefield select expression radio button, and in the value field click the edit button as shown below.

    BankLOVSwitcher attribute

  9. After you click the edit button, the Edit Expression builder window will be shown, enter the following expression
    if(UserLocale==’ar’) return ‘ar_LOV_Bank’
    else if(UserLocale==’en’) return ‘en_LOV_Bank’
    and in the available area select the the UserLocale attribute and shuttle it to the selected area as shown below, then press OK.

    BankLovSwitcher attribute value and dependency

  10. Now, select your Bank attribute, in the List of Values: Bank section, and from the List of Values Switcherlist select BankLOVSwitcher attribute. and select your default LOV as shown below.

    LOV switcher

  11. Now, all you need in your application is to add a simple method, this method should set the UserLocale attribute to ar when the user select or click the Arabic locale and set it to en when the user change to English locale.



Filed under ADF

9 responses to “Internationalize LOV using switcher

  1. Hi My Friend i am Chaddy good tutorial , i was wondering how can i change the location of the menubar items aligment from right to left and viseversa ?

  2. could you please tell how to complete the 11) step programatically.
    i think that is the most important step.

  3. hi Mohamed,
    thanks for this sample, but same as lechi, in my case, my first login page contain the language and i can access to the language from any pages using #{sessionScope.loginBean.lang},

    so in my case how can i set userLocal of my view object


    • Mohammad Jabr

      Hello Fakhri,
      You can try to override the prepareSession() method in the ApplicationModuleImpl class, once the user selects the locale, you can set the UserLocal attribute.

      • Thanks for your replay Mohammed,
        but i did not find this method in my ApplicationModuleImp Class, second it will be usefull next time, can you make suggestion about the solution I found , it’s just to override the getter methode in the RowImpl Class
        public String getuserlocale() {
        return (getApplicationModule().getSession().getLocale().getLanguage());
        //return (String) getAttributeInternal(USERLOCALE);

        In my case that’s fine and works well,

        • Hi Mohamed,
          about your solution I think that we have to implement all the detail listed above, for example if bank id existe in 10 tables, so we need to implement 10 times userlocale, bankLovSwitch and create 2 or 3 lov for each view object.
          I think that i have better solution but same idea,:
          in Bank view object we create userlocale and varBankName, and the value of varBankName will take one of these value:
          if(userlocale==’en’) return BankName
          else if(userlocale==’ar’) return BankNameAr
          else if(userlocale==’fr’) return BankNameFr

          and just we modify in the LOV of the BankId to use varBankName attribute

  4. Hi Med,
    I find a solution how to get userlocale and i want to share it in your blog:
    in the rowImpl class, just modify :
    public String getuserlocale() {
    return (getApplicationModule().getSession().getLocale().getLanguage());
    //return (String) getAttributeInternal(USERLOCALE);

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s