Popular Posts

Sunday, December 29, 2013

Internationalizing and Localizing Pages in ADF



Internationalization means building your application so it can be adapted to different languages and countries. Localization means actually preparing your application for a specific language and country. This will involve translating the user interface text,but also changing date formats and making other changes for the specific country.

How localizable strings are stored? There are three ways to store localizable strings in an ADF application: 
* In a simple .properties file.
           – This is the easiest way to work with localization. 
* In an XLIFF file (an XML file format). 
           – XLIFF stands for XML Localization Interface File Format. 
           – If you will be using a professional translation service to translate the user-visible text strings, they are likely to ask you for an XLIFF file. 
           – Professional translation software will be able to read and write XLIFF files. 
* In a Java ListResourceBundle class. 
           – This option is to define all your strings in a Java class that extends java.util.ListResourceBundle. 
           - This class must implement a method to return all the localizable strings in an Object.

Steps of internationalizing your application using .properties file :
1. Create new fusion application


2.Prepare your files that hold the labels text and the opposite translation




hint: this file must be .properties extension but the name is not mandatory unless for secondary language must end with _ex(_ar for Arabic)



3.Duplicate these steps for the Arabic version of this file but the name must be LocaleFile_ar.properties.


4.Create your page that will be used




5.Add components that will be used in your page, you’ll need a text item as an example for an item to be translated and 2 links or buttons for English-Arabic switch


6.You will need to drop a component (set action listener) from operations category on each button and set their values as in pictures below:





7.Change the path of resource bundle in the 2 projects as follow:



8.Enter a label for our item as follow:



9.Open your resource file


10.Copy a value from English source to Arabic one with different description like:


11.Open View Controller ->Web Content ->WEB-INF -> faces-config.xml and add the name of the class that will be created soon


12.Implement this class ‘PhaseListener’ and override this procedure ‘beforePhase’ and this function ‘getPhaseId’





13.Override these procedures with this snippet of code
beforePhase:
String locale;
locale = (String)JSFUtils.getFromSession(“locale”);
if(locale!=null)
phaseEvent.getFacesContext().getViewRoot().setLocale(new Locale(locale));
getPhaseId:
return PhaseId.RENDER_RESPONSE;
14.You will need to add these files into your application









Hint #1: you have to modify the package in the top of JSFUtils file instead of psystems to your package path where your file placed.
Here : package com.vzmymate.view;
Hint #2: you have to modify the package in the top of ADFUtils file instead of psystems to your package path where your file placed.
Here : package [ com.vzmymate.view; ] & replace the import of JSFUtils to [ import com.vzmymate.view.JSFUtils ; ]
15. Add the resource bundle to your application from faces-config file


16.Run and enjoy.