Jasper Reports Internationalization - JasperReports

What is Internationalization in Jasper Reports?

At some instances the reports are required in different languages and it involves a lot of work redundancy in writing the same report in different languages. In such cases report internalization comes to rescue as it facilitates in writing only some pieces of text which differ from language to language. The reports writing through internationalization can be run everywhere.

What are the steps to generate report in different languages and the features of report Internationalization?

The following are the steps to generate a report in different languages:

  • The resource bundle java.util.ResourceBundle is being associated with the report template. This can be done in two ways – at the time of design by setting the resourcebundle attribute to target resource bundle base name and by allowing a dynamic/runtime association by supplying the a java.util.ResourceBundle object during report filling time. Added to these two the built-in REPORT_LOCALE parameter can be used to generate the report in a locale.
  • The report expressions facilitates with a syntax $R{} for enabling report internationalization, which is made inside the expressions of the report such that the java.lang.Stringresources reference can be placed inside the java.util.ResourceBundle object.

The string value is extracted from the resource bundle and the title of the report is displayed, by using the report template which is based on runtimesupplied locale.

  • An built-in method is provided inside the net.sf.jasperreports.engine.fill.JRCalculator report for formatting the messages in different languages. The functions provided by this method are similar to that of the java.text.MessageFormat class. Three signatures are facilitated by this method for using three message parameters.
  • A built-in str() method (the equivalent of the $R{} syntax inside the report expressions), That enables the access to the resource bundle content
  • The -in REPORT_TIME_ZONE parameter is used for formatting data and time and ensuring that the transformation of the time is in order.
  • The text run direction information is made available in the library such that the documents that are generated in right-to-left writing are properly rendered.
  • The button ToolTips need to be adapted for internationalization if the application relies in the built-in swing viewer. It is very simple as viewers are made reliable on the resource bundle which is predefined and has to extract information that is locale-specific information. net.sf.jasperreports.view.viewer is considered as the resource bundle base name.


Internationalization is demonstrated by writing a new report template (jasper_report_template.jrxml).The contents of the JRXML file are saved to C:\tools\jasperreports-5.0.1\test directory.

By the above code, the Jasper Reports are guided by the resourcebundle attribute for usage of the localized strings for the report. A property file need to be created such that the root name matches with the value of the attribute. When the report is filled, the file must exist anywhere in the CLASSPATH. In the above example, property file localizationdemo.properties is saved under the directory C:\tools\jasperreports-5.0.1\test. The contents of this file are as shown below:

The name of the file has to be localizationdemo[locale].properties for using different locale. In this example a file for Spanish locale is written. The file is saved as C:\tools\jasperreports-5.0.1\test\localizationdemo_es.properties. The contents of this file are as follow −

The value of the resourceBundle property is obtained by the syntax $R{key}.

A value is assigned to the built-in parameter if the locale that is to be used is known. The name of the parameter is defined as REPORT_LOCALE and is defined in net.sf.jasperreports.engine.JRParameter class and the value of the constant is an instance of java.util.Locale. The file is saved to C:\tools\jasperreports-5.0.1\test\src\com\wisdomjobs directory. The contents of the file are as follows −

How the report is generated using Internationalization in Jasper Reports?

The above file is compiled and executed by using the ANT build process. The file contents are saved under the C:\tools\jasperreports-5.0.1\test as shown below. The import file is to be placed in the same directory as build.xml which is extracted from the chapter Environment Setup

Open command line window and go to the directory where build.xml is placed. Execute the command ant -Dmain-class=com.wisdomjobs.JasperReportFillI18 as follows:

The compilation of the above code results in a JasperViewer window that appears as follows:

Report i18 Example

All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

JasperReports Topics