Jasper Report Localization Customization
Objective
You want to provide localized versions of your Jasper reports.
Background
In Windchill Reports, there are both the Data Source and Report objects that contain text that can be localized. Localizing the text in these objects allows the text to be displayed in the locale you have configured.
Scope/Applicability/Assumptions
This documentation provides information about localizing Jasper Reports. The assumptions are:
• You have created the ReportTemplate, <MyReportTemplate> in the site context.
• You have created a Windchill Report object, <MyReport> in the site context.
• You have placed a Jasper Report <MyJasperReport>.jrxml under <customizationRootDirectory>/<module>/main/resources/JasperReports/<ReportFolder>.
• You have placed the related locale property files under <customizationRootDirectory>/<module>/main/resources/JasperReports/<ReportFolder>.
For the WBR integration, you must also have access rights to update the reporting meta model. This document describes procedures for using standard Java resource bundles to externalize text used in the WBR system. To support localized text, a language-specific resource bundle must be created, with the text translated to the appropriate language. It is assumed that you require support for more than one language, and you have the ability to translate text to your supported languages. The text elements that are referred to in this document consist of report names, parameters, and columns. The actual data displayed in WBR reports is returned from Data Sources. Localizing this data is not covered in this document.
Intended Outcome
The result of this solution is the use of your WBR reports in more than one language based on the client locale.
Solution
Generating the external localized text to Java resource bundles that can be translated to support a specific client locale.
Prerequisite knowledge
To achieve this objective, you need to be familiar with the following:
• Report Management User Interface
Solution Elements
|
Element
|
Type
|
Description
|
|
<MyReportTemplate>WindchillReportTemplate
|
Windchill Object
|
The Windchill object that specifies a query for retrieving Windchill data.
|
|
<MyReportTemplateResource>
|
Resource Bundle Info Properties File
|
The resource bundle info file used to localize ReportTemplate text items.
|
|
<MyReport>WindchillReport
|
Windchill Object
|
The Windchill object that is displayed to the users in the Windchill user interface.
|
|
<MyReportResource>
|
Resource Bundle Info Properties File
|
The resource bundle info file used to localize Report text items.
|
Procedure - Localizing a ReportTemplate Data Source
1. Create the java resource file by extending wt.util.resource.WTListResourceBundle. Add entries, as necessary, for the task method name, parameter names, and column names. Create the language-specific versions of <MyReportTemplateResource>.java, and place them under <customizationrootdirectory>/<module>/main/src. Compile them using the ant compile, deploy commands of CCD.
2. To update <MyReportTemplate> to specify the resource bundle, navigate to > > .
3. Right-click <MyReportTemplate> and select Edit Report Template to launch Query Builder.
4. In the Edit Report Template dialog box, under Additional Properties, enter <MyPackage>.<MyReportTemplateResource> in the Resource Bundle box.
5. Click Apply and then Save.
Procedure - Localizing a Windchill Report Object's Name
1. Create the java resource file by extending wt.util.resource.WTListResourceBundle at the path <customizationrootdirectory>/<module>/main/src.
2. Add an entry for the Report Object's Name.
3. Create the language-specific versions of <MyReportResource>.java and place them under <customizationrootdirectory>/<module>/main/src
4. Update <MyReport> to specify the resource bundle. Navigate to the Windchill > page.
Select Edit for <MyReport>.
5. Enter <MyPackage>.<MyReportResource> into the Resource Bundle field and click OK.
6. Verify that the report attribute LocalizedName, is the translated text, based on the client locale.
Localizing a Jasper Report
For localizing a Jasper report, refer to the JasperSoft documentation.
Assume that you have created related locale files, under <customizationrootdirectory>/<module>/main/resources/JasperReports/<ReportFolder>.
References:
Sample Code
<?xml version = "1.0" encoding = "UTF-8"?>
<!DOCTYPE jasperReport PUBLIC "//JasperReports//DTD Report Design//EN"
"http://jasperreports.sourceforge.net/dtds/jasperreport.dtd">
<jasperReport xmlns = "http://jasperreports.sourceforge.net/jasperreports"
xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation = "http://jasperreports.sourceforge.net/jasperreports
http://jasperreports.sourceforge.net/xsd/jasperreport.xsd"
name = "jasper_report_template" language = "groovy" pageWidth = "595"
pageHeight = "842" columnWidth = "555" leftMargin = "20" rightMargin = "20"
topMargin = "20" bottomMargin = "20" resourceBundle = "localizationdemo">
<title>
<band height = "552">
<textField>
<reportElement positionType = "Float" x = "150" y = "20"
width = "400" height = "50"/>
<textElement>
<font size = "24"/>
</textElement>
<textFieldExpression class = "java.lang.String">
<![CDATA[$P{REPORT_LOCALE}.getDisplayName ($P{REPORT_LOCALE})]]>
</textFieldExpression>
</textField>
<textField isStretchWithOverflow = "true" isBlankWhenNull = "true">
<reportElement positionType = "Float" x = "20" y = "125"
width = "530" height = "20"/>
<textElement textAlignment = "Justified">
<font size = "14"/>
</textElement>
<textFieldExpression class = "java.lang.String">
<![CDATA[$R{localization.text1}]]>
</textFieldExpression>
</textField>
</band>
</title>
</jasperReport>
Examples of Usage in Windchill Code
All out-of-the-box reports are localized for all Windchill supported locales.
Related Packages/Class Javadoc
• Foundation module
wt.query.template
• Reporting module
com.ptc.windchill
Other Related Windchill Documentation
• Report Management online help