Translations and user information in Jasper Reports

Albert Cervera i Areny Dec 1, 2009

We've recently improved a couple of things in the jasper_reports module for OpenERP which you'll find in bazaar.

User fiell

One of them is the addition of a virtual relation field called User. This new field gives the report designer access to all the information related to the user who is executing the report, which is specially interesting in those documents that don't have a direct or indirect relation with the company, such as sale/purchase orders or pickings.

/file/user-field.png

The recently added User field, at the end of the field list for the stock.picking model.

i18n under iReport

Another improvement has been in the translations area. In order to ease report design, we've modified the Java code so it is possible to use our i18ngroovy language within iReport. Here are the steps you need to follow in order to configure iReport (libraries can be found in jasper_reports/java/lib):

Adding the gettext library

If you work under Linux go to menú option Tools -> Libraries, click on New Library... button. Set Library Name to "i18n" and add new JAR: "gettext-commons-0.9.6.jar"

/file/library-manager.png

Configuring gettext library under Linux

Adding the i18n library

Go to menú option Tools -> Options -> Classpath. If you work under Linux add new JAR "i18n.jar". If you work under Windows you should also add the "gettext-commons-0.9.6.jar" file we added in the previous step under windows.

/file/classpath.png

Configuring i18n library under Linux

Adding the i18ngroovy property

Go to menú option Tools -> Options -> Jasper Properties and add a new property: called net.sf.jasperreports.compiler.i18ngroovy with value com.nantic.jasperreports.I18nGroovyCompiler

/file/properties.png

Configuring i18ngroovy property

Note that windows users will be annoyed by the fact that this property is not remembered by the application when you restart it (at least with version 3.5.3) and thus has to be reset each time you open iReport. We hope iReport guys fix this issue in upcoming versions.

Setting report's Language

Once everything is configured you can use the new i18ngroovy language in your reports.

/file/i18ngroovy.png

Setting report's language to i18ngroovy

Usage

Now you can freely use the tr() set of functions to translate your reports and preview them within iReport. For example, in the following report we have the L variable defined as $F{Idioma-lang} != null && $F{Idioma-lang}.length() == 5 ? new Locale( $F{Idioma-lang}.substring(0,2), $F{Idioma-lang}.substring(3,5) ) : ( $F{Idioma-lang} != null && $F{Idioma-lang}.length() == 2 ? new Locale( $F{Idioma-lang}.substring(0,2) ) : $P{REPORT_LOCALE} ).

/file/tr.png

Using tr() functions under iReport

/file/preview.png

Report preview under iReport

Note that reports that use Groovy instead of i18ngroovy will still work when run under OpenERP. This is only necessary for previewing reports that use NaN's translation system

Top