You can adapt reports to global audiences by localizing input controls and field names:
• Input controls – The server supports multi-lingual prompts and static lists of values in reports.
• Field names – The server supports multi-lingual field names in reports.
A $Rexpression that you write in the report design triggers linguistic changes in the report output for different locales. Each $R expression refers to a name-value pair (your translations) in a resource bundle. A resource bundle file is a text file that has a .properties extension. You create a resource bundle in iReport or a text editor. You set the base name of the resource bundle in the header of the JRXML file:
<jasperReport name=”StoreSales” pageWidth=”595” pageHeight=”842” columnWidth=”515” leftMargin=”40” rightMargin=”40” topMargin=”50” bottomMargin=”50” resourceBundle=”simpleTable”> |
For example, simpleTable is the base name of the resource bundle file for this report. If you prefer using a graphical user interface to coding in XML, use iReport Designer to set the base name of the resource bundle, as explained on See "To set the base name of the resource bundles in the JRXML Topic:".
In this procedure, you run the Romanian version of the complex report that you added in section Uploading Undetected File Resources.
To run the Romanian version of the complex report:
1. Choose the Romanian locale on the login page of the server, and login as an administrator.
2. Click View Repository, and navigate to Organization Reports Samples.
3. Click the name of the complex report, New Complex Report.
The Input Controls dialog appears.
4. Enter input control values:
Text Input Control: 3
a. | Check Box Input Control: Check the check box. |
b. | List Input Control: Select Third Item. |
c. | Date Input Control: Click , and select March 31, 2010. |
d. | Query Input Control: Select Sarah Smith from the drop-down. |
e. | Click OK. |
The fields in the title band and column names (sales person, sales account, and sales amount), shown in See "A Report Localized for the Romanian Locale", appear in the language set by the Romanian resource bundle: sales_ro.properties.
title=Raport al v\u00E2nz\u0103rilor lunare sales.person=Agent de v\u00E2nz\u0103ri sales.account=Client sales.amount=Sum\u0103 param.number=Num\u0103r param.date=Dat\u0103 |
The currency and dates in the report output header map to Romanian locale settings.
|
By default, the web interface elements appear in US English when you choose an unsupported locale, such as the Romanian locale. If you choose a supported language, the web interface elements appear in that language. Supported languages are Chinese (Simplified), French, German, Japanese, and Spanish. You can customize the server to support additional languages; you can translate the web interface into a different language, server property names, and messages in another language. For some locales, you may also need to change the default locale and time zone. For more information about localizing the server, see the JasperReports Server Administrator Guide.
This section describes how to create an Ad Hoc report that prompts for input multiple languages. The tasks are:
• Set the base name of the resource bundles in the JRXML Topic.
• Create resource bundles that contain translations for the prompts.
• Create an Ad Hoc report based on the JRXML Topic.
• Edit an input control to make prompts multi-lingual.
• Upload the resource bundles.
• Run the report and use the localized input control.
The order of these tasks is important: Set the base name of the resource bundle in the JRXML Topic first, then create the Ad Hoc report. If you open the JRXML Topic after creating an Ad Hoc report, iReport removes grouping or sorting of data if there is any.
To set the base name of the resource bundles in the JRXML Topic:
1. Start iReport. In iReport, click Window JasperReports Server Repository.
The Repository Navigator appears.
2. In the Repository Navigator, set up a connection to the server as described in section Connecting to the Server from iReport.
3. Navigate to Ad Hoc Components Topics and right-click the JRXML topic for this report: Parametrized Report.
4. Select Copy.
5. Navigate to the Reports folder, right-click, and select Paste. The Parametrized Report topic appears in Reports.
6. To open the topic in the Designer tab, expand the Parametrized Report folder and double-click its main JRXML: ParametersJRXML_label. The Shipping Report appears in the Designer tab.
7. Click Window Report Inspector.
8. In the Report Inspector, right-click the root node: ParamMany.
In the main JRXML, ParamMany is the report name.
9. From the context menu, choose Properties.
See "Selecting Properties of the ParamMany report" shows the ParamMany root node and Properties context menu.
|
The ParamMany Properties dialog appears.
10. In the ParamMany Properties dialog, set the base name of the resource bundle to freight:
Scroll down to the Resource bundle property.
f. | Click . |
g. | Enter freight. |
See "Setting the Base Name of the Resource Bundle" shows the properties of the ParamMany report.
|
11. Click OK to close the ParamMany - Resource bundle dialog.
12. Click Close to close the ParamMany - Properties dialog.
13. Click File Save to save the resource bundle name to the JRXML.
14. In the Repository Navigator, right-click ParametersJRXML_label. and choose Replace with Current Document.
|
Saving the Current Document in iReport to the Repository |
The modified JRXML with a base resource bundle name overwrites the Parametrized Report Topic in the repository.
To create resource bundles that contain translations for prompts:
1. In a text editor, create a new file for English translations, and enter these name-value pairs in the file:
BundleCountry = Country BundleDate = Date BundleOrder= Order |
2. Save the file as freight.properties.
|
The file name of the default (English) resource bundle consists of the base name of the resource bundle and the properties extension. |
3. In a text editor, create a new file for French translations, and enter these name-value pairs in the file:
BundleCountry = Pays BundleDate = Datte BundleOrder = Pour ID |
4. Save the file as freight_fr.properties.
|
The file name of a localized resource bundle follows this Java naming convention: <default_file_name>_<locale>.properties
|
To create an Ad Hoc View based on the JRXML Topic:
1. Log into the server as administrator, and choose Create Ad Hoc View.
2. In the Data Chooser wizard, navigate to Ad Hoc Components Topics, on the Topics tab, choose Parametrized Report.
3. Click Table. The Parametrized Report topic (a blank report) opens in the Ad Hoc Editor.
4. In the Measures list, double-click these fields:
• Order ID
• Freight
5. Right-click the Customer Id field and select Add as Group.
6. Click Click to add a title, and enter Multi-lingual Input Prompts View.
|
Creating an Ad Hoc View |
7. Click , select Save Ad Hoc view As and Create Report. In the Save As dialog, select the Ad Hoc Reports folder, and enter:
Data View Name: Multi-lingual Input Prompts View
Data View Description: A report that prompts for input in French and English.
Report Name: Multi-lingual Input Prompts View Report
8. Click Save.
To edit an input control to make prompts multi-lingual:
1. In the server, click View Repository.
2. Locate the Multi-lingual Input Prompts View Report, right-click it, and choose Edit.
The JasperReport wizard appears.
3. Click Controls & Resources. The Controls & Resources page lists these input controls:
• Country
• RequestDate
• OrderID
4. Click the Country input control.
5. On the Locate Input Control page, click Next to define an input control in the next step.
6. On the Create Input Control page, change the prompt text from Country to this expression:
$R{BundleCountry}
See "Entering a $R Expression in the Prompt Text Field" shows this expression entered in the prompt text field.
|
7. Click Next.
8. Accept the default settings on subsequent pages by clicking Next and Save:
On the Locate Query page, click Next.
h. | On the Name the Query page, click Next. |
i. | On the Link a Data Source to the Query page, click Next. |
j. | On the Define the Query page, click Save. |
9. On the Set Parameter Values page, click Submit.
The Controls & Resources page now shows the $R{BundleCountry} expression instead of Country at the top of the list of input controls:
|
Input Controls Include One Multi-lingual Input Control |
10. Change the prompt text of the other input controls in a similar manner:
Repeat See "Click the Country input control." through See "On the Create Input Control page, change the prompt text from Country to this expression:" to change the RequestDate and OrderID input controls to these expressions:
RequestDate: $R{BundleDate}
OrderID: $R{BundleOrder}
k. | Accept the default settings on subsequent pages of the JasperReport wizard by clicking Next and Save. |
The Controls & Resources page now shows the $R expressions for all three input controls.
To upload the resource bundles:
1. On the Controls & Resources page, click Add Resource.
The Locate File Resource page appears.
2. On the Locate File Resource page, select Upload a Local File.
3. Click Browse, locate the freight.properties file, select the file, and click Open.
4. On the Locate File Resource page, click Next.
On the Add a Report Resource page, freight.properties appears as the Selected Resource, indicating that the server automatically detected it as a resource bundle.
5. On the Add a Report Resource page, enter these properties:
• Name – freight.properties
• Resource ID – freight.properties
|
• Description – Default English resource bundle
6. Click Next. The list of resources on the Controls & Resources page now includes the resource bundle freight.properties.
7. On Controls & Resources, click Add Resource again, but this time, upload the French resource bundle:
On the Controls & Resources page, click Add Resource again.
l. | Select Upload a Local File, click Browse, locate the freight_fr.properties file you created, select it, and click Open. |
m. | In Locate File Resource, click Next. The Add a Report Resource page appears: |
n. | Enter the following information: |
Name – freight_fr.properties
Resource ID – freight_fr.properties
Description – French resource bundle
8. Click Next.
The Controls & Resources page shows the English and French resource bundles in the resources list.
9. Click Submit.
To run the report and use the localized input control:
1. Click Log Out.
2. On the Login page, click Show locale & time zone.
3. Select the en_US-English (United States) locale, and log into the server as an administrator.
4. Run the Multi-lingual Input Prompts Report.
The report appears in the report viewer:
|
Viewing the Report in English |
5. Click Options.
The input controls appear with English prompts.
6. Click Log Out.
7. On the Login page, click Show locale & time zone.
8. Select the fr - French locale, and log in as administrator.
9. Run the report again and click Options.
See "Input Control Prompts in English and French" shows the input controls that with English and French prompts.
|
The server provides linguistic support for the list of values that an input control can present to users. The input controls that can present a list of values are:
• Single-select list of values
• Single-select list of values (radio)
• Multi-select list of values
• Multi-select list of values (check box)
See "A Multi-select List of Values in English and Spanish" shows an example of the multi-lingual Department Report in the Reports/Samples folder (if you installed sample reports during installation). The prompts and the multi-select list of values appear in English or Spanish, depending on the locale you select on the login page.
|
The next example shows how to localize an input control that presents a single-select list of values. These tasks are explained step-by-step:
• Add a multi-lingual static list of values to a list input control.
• Create a new resource bundle for the French translations.
• Upload the French resource bundle.
• Create a new resource bundle for the English translations.
• Replace the existing English resource bundle with the new one.
• Remove unwanted parameters from the sample report design.
• Run the report that uses a multi-lingual list of values in an input control.
You edit a sample report to localize the list input control. To the list input control, you add a multi-lingual list of values for the US English and French locales.
To add a multi-lingual static list of values to a list input control:
1. Log into the server as administrator and add a folder to the repository named Temp.
2. Locate the Sales By Month report in the Reports Samples folder of the repository. Select it and click Copy.
3. Navigate to the Temp folder and choose Paste. The Sales By Month Report appears in the Temp folder.
4. Select the Sales By Month Report and click Edit.
The JasperReport wizard appears.
5. Click Controls & Resources.
The report has five input controls, including a List Input Control, two resource bundles, and other resources, as shown in Input Controls and Resources.
6. Click the List Input Control to edit it.
7. In Locate Input Control, click Next.
8. On the Create Input Control page, change the prompt text from List Input Control to $R{department_multi}.
See "A $R Expression in the Prompt Text Field" shows the $R expression in the Prompt Text field.
|
9. Click Next.
10. On the Locate List of Values page, click Next. The Edit List of Values page appears.
11. On the Edit List of Values page, click Remove to remove each existing name-value pair.
12. Add these name-value pairs:
Name |
Value |
$R{department_1} |
1 |
$R{department_2} |
2 |
$R{department_3} |
3 |
See "The Revised List of Values Containing $R Expressions" shows the edited list of values containing the $R expressions in the name fields.
|
13. Click Submit.
The Controls & Resources page shows the change to the input control prompt. The expression $R{department_multi} replaces List Input Control in the list of input controls.
14. Click Submit again to save your work.
To create a new resource bundle for the French translations:
1. In a text editor, create a new file for French translations, and enter these name-value pairs for the input control:
department_multi=Choisir le service department_1 = Travail # 1 department_2 = Travail # 2 department_3 = Travail # 3 |
2. At the bottom of the file, enter these field and property translations to localize the report:
title=Rapport de ventes mensuelles sales.person=Commercial sales.account=Compte sales.amount=Montant param.list=Liste Détaillée |
|
3. Save the file as sales_fr.properties to your hard drive.
To upload the French resource bundle:
1. Assuming you are still logged into the server, select the Sales By Month report, and click Edit.
2. On the Controls & Resources page, click Add Resource.
3. Select Upload a Local File, click Browse, and locate the sales_fr.properties file on your hard drive. Select the file, and click Open.
4. In Locate File Resource, click Next.
On the Add a Report Resource page, sales_fr.properties appears as the Selected Resource, indicating that the server automatically detected it as a resource bundle.
5. On the Add a Report Resource page, enter this information:
• Name – sales_fr.properties
• Resource ID – sales_fr.properties
|
6. Click Next.
The Controls & Resources page appears.
To create a new resource bundle for the English translations:
1. In a text editor, create a new file for English translations, and enter these input control name-value pairs in the file:
department_multi=Select Department department_1=Work #1 department_2=Work #2 department_3=Work #3 |
2. At the bottom of the file, enter these field and property translations to localize the report:
title=Sales By Month Report sales.person=Sales person sales.account=Account sales.amount=Amount param.list=List item |
3. Save the file as sales.properties to your hard drive.
To replace the old English resource bundle in the repository with the new one:
1. Assuming you are still logged into the server and editing the Sales By Month report, remove the old sales.properties resource bundle:
On the Controls & Resources page, select sales.properties.
o. | Click Remove. |
2. Click Add Resource.
3. On the Locate File Resource page, select Upload a Local File, click Browse, and locate the new sales.properties file that you created in the previous procedure. Click Open.
4. Click Next.
On the Add a Report Resource page, sales.properties appears as the Selected Resource, indicating that the server automatically detected it as a resource bundle.
5. On the Add a Report Resource page, enter this information:
• Name – sales.properties
• Resource ID – sales.properties
|
6. Click Next.
7. On Controls & Resources, click Submit.
At this point, the report does not run because the sales.properties file does not contain name-value pairs for all parameters that the JRXML defines. In the next procedure, you remove these parameters from the report.
To remove unwanted parameters from the sample report design:
This procedure assumes you finished procedures in section Adding Multi-lingual Prompts to Input Controls and are still connected to the server from iReport using the JasperReports Server Plug-in. In this procedure, you remove elements in the title band that lists parameter names and settings in the report output header.
1. In the Repository Navigator, expand the Temp and Sales By Month Report folders, then double-click Sales By Month Jasper Report.
The JRXML report appears in the Designer tab.
2. Ctrl-click to select all elements in the title band except $R{title}, $R{param.list}, and $P{ListInput}.
See "Selecting Elements to Remove from the Title Band" shows the selected elements in the title band.
|
3. Right-click an empty area in the Designer tab, and choose Delete. If you have empty elements after the last step, delete them.
See "Elements Remaining in the Title Band" shows the remaining elements.
|
There’s too much white space in the title band.
4. To remove excess white space:
Drag a selection box around the $R{param.list} and $P{ListInput} elements.
p. | Press the Arrow key on the keyboard to move the elements upward. |
q. | Drag the bottom margin of the title band upward to reduce its height. |
5. Remove the actual parameters from the report:
Choose Window Report Inspector.
r. | In the Report Inspector, expand Parameters, scroll to the bottom of the parameter list, and Ctrl-click to select these parameters: |
TextInput
CheckboxInput
DateInput
QueryInput
LoggedInUser
s. | Right-click the selected parameters and select Delete. |
|
Deleting Unwanted Parameters From the JRXML |
6. Click Yes to confirm that you want to delete the items.
7. From iReport, remove the input control resources from the report unit in the repository.
In the Repository Navigator, expand Input Controls in the report unit Sales By Month Report.
|
Expanding the Input Controls Folder |
t. | Ctrl-click to select these input control resources: |
Text Input Control
Checkbox Input Control
DateInput_label
QueryInput_label
u. | Right-click the selected resources and click Delete |
Answer Yes to each prompt to confirm the deletion of the resource.
8. Right-click the Sales By Month Jasper Report JRXML, and choose Replace with Current Document.
|
Saving the Modified JRXML to the Repository from iReport |
9. Click Yes when asked if you want to save the file before sending its content to the server.
10. Click View Repository, navigate to the Temp folder, and select the Sales By Month Report. Click Edit.
See "Controls & Resources Listing Only One Input Control" shows the JasperReport wizard on the server. Only one input control remains in the report.
|
To run the report that uses a multi-lingual list of values:
1. Click LogOut. On the server login page, click Show locale & time zone, select the en_US-English (United States) locale, and log into the server as an administrator.
2. Navigate to the Temp folder of the repository, and click the name of the Sales By Month Report to run the report.
The Report Viewer presents the report using English field and property names in the report.
3. Click Options, and select the drop-down.
The prompt and list of values appear in English, as shown in A List of Values in English and French.
4. Logout, on the server login page, click Show locale & time zone, select the fr_French locale, and log into the server as an administrator.
5. Navigate to the Temp folder of the repository, and click the name of the Sales By Month Report to run the report.
See "Viewing Report Output for the French Locale" shows the report output: the French report title, field, and property names defined in the resource bundle. The server formats the currency using a comma instead of a decimal point to separate Euro cents from dollars. Translation packs and resource bundles installed with the server for the French locale are used to format currency and dates and to translate web interface components.
|
6. Click Options, and select the drop-down. The input control prompt and static list of values appears in French.
See "A List of Values in English and French" shows the input control prompt and static list of values in English and in French.
|
The location of a resource bundle determines its capability for being reused and conditions under which the server uses it. To resolve a $R expression in a report, the server scans resource bundles at two levels in the order described in this table.
Order |
Level |
Description |
1 |
Report/ Repository |
A report-level bundle declares the resource bundle base name in the header of its JRXML file. The Romanian resource bundle is a report-level bundle. A repository-level bundle is independent of any specific report and can be linked to multiple reports, as described in section Locale Bundles). |
2 |
Server |
A server-wide bundle typically contains server messages and labels of user interface components, as described in the JasperReports Server Administrator Guide. This bundle typically resides in the WEB-INF/bundles directory of the server. |
First, the server searches the report/repository level and stops scanning resource bundles if it finds a resolution to the $R expression. If the server does not find a resolution, it scans the server level for the resource ID of the field and uses this ID.
By default, the server uses three fonts you can use in reports:
• DejaVu Sans
• DejaVu Serif
• DejaVu Sans Mono
Using the DejaVu fonts shipped with the server ensures availability of fonts in all environments; the PDF is pixel-perfect every time.
The DejaVu fonts replace the Java logical fonts used in previous versions of the server:
• SansSerif
• Serif
• Monospaced
|
SansSerif, Serif, Monospaced can still be used, but are deprecated because these Java logical fonts map to different TTF files in different environments, and run the risk of text being cut when exported to PDF due to font metric mismatches. Also, these Java logical fonts aren't recognized by some browsers, resulting in font substitutions. For example, Firefox in a Windows environment renders the SansSerif logical font as Serif. |
When using the DejaVu fonts coming from JasperReports font extensions, you don’t need to set any other font attributes (such as the pdfXXX attributes) in the JRXML or specify font mapping. The font extension file that makes these fonts available sets font attributes and mapping.
For more information about DejaVu, refer to its SourceForge project at:
http://dejavu-fonts.org/wiki/index.php?title=Main_Page.
|
When you upload a TrueType font to the repository, the file name must include the correct extension (.TTF). |