BIRT: Making internationalized reports

BIRT is widely used as a reporting tool in business intelligence projects. These days every client has a very first requirement that application must be multilingual. They want their customers to see application in their local languages.  Java provides great features to make an application multilingual. We have used BIRT in one of our project and Client wanted us to have reports in multiple languages. I am writing an article on how we had achieved localization in BIRT by using BIRT feature for localization and also using JavaScript as BIRT’s inbuilt feature for localization will not work in all the cases.

As you can see the first image which is a non-localized report with a table. The header and column names are not localized till now.

In the next step as shown above we have added a properties file that will externalize the column labels and headers names. So for different language we will have different properties file. Name of the properties will contain locale. For example for French we will have messages_fr.properties file. So when a request will come for report access according to the locale fetched from request object the report will be generated in that particular language.

In third step click on any of the column header and in the property editor go to the localization. In that click on browse button that will give you option to select one of the properties from the properties file. This is a standard way of localizing a label. This functionality is provided by BIRT itself.

As shown above in this case we have a different kind of content in the column. In this case we have to use JavaScript for localization.

As done we can use an external JS file (in this case utils.js). Code of this JS will be explained later.

Method from this JS file will be used as shown below in the image. This method gives us the value based on the passed key from the properties file.

function getPropValue(keyFromProperties,locale,defaultValue){

 importPackage(Packages.java.lang);

 var value = reportContext.getMessage(keyFromProperties);

 if((value!=null)&&(!value.equals(""))){
  return  value;
 }
 return defaultValue;
}

As you can see this is a very simple method. BIRT uses rhino javascript so you can access Java packages from JavaScript as done for the java.lang.  reportContext will give you access to the context of the report design from which you can get a value by passing a key.
After this if you will run the report design you will be able to see the following report. This is localized. This is very useful feature of BIRT and will be really helpful for the developers who want to make reports multilingual.

Share on : Twitter, Facebook or Google+