iReport Ultimate Guide - Nimsoft Library

iReport Ultimate Guide - Nimsoft Library iReport Ultimate Guide - Nimsoft Library

13.07.2015 Views

iReport Ultimate GuideFigure 17-4The resource bundle in the Favorites viewThe bundle node in Favorites provides several tool features. Right-click the file node to open one of the editing tools for theresource bundle:• Edit. Opens a resource bundle as a text file (see Figure 17-3)• Open. Opens the visual resource bundle editor that shows at the same time the translations for all the language you aresupporting (see Figure 17-5).Figure 17-5Visual Bundle EditorTo add a new locale (meaning support for a new language), right-click the resource bundle node and select the menu item Addlocale.... This will pop up the window shown in Figure 17-6. It is used to set the correct language specifications (language,country and optionally a variant code).326

InternationalizationFigure 17-6New localeBy confirming the choice, a new file will be created in the same directory as the default one; it will have the proper localizationabbreviation appended to the file name, and it will be visible as a child of the bundle node in the Favorites view.17.2 Retrieving Localized StringsThere are two ways to retrieve the localized string for a particular key inside a JasperReports expression:• Use the built-in str("key name") function• Use the special syntax $R{key name}Here is an example expression for retrieving a localized string:$R{hello.world}UR converts the text associated with the key hello.world using the most appropriate available translation for theselected locale.17.3 Formatting MessagesThe internationalization features included with UR are based on the support provided by Java. One of the mostuseful features is the msg function, which you can use to dynamically build messages using arguments. In fact, msg usesstrings as patterns. These patterns define where arguments, passed as parameters to the msg function, must be placed. Theposition of an argument is expressed using numbers between braces, as in this example:“The report contains {0} records.”The zero specifies where to place the value of the first argument passed to the msg function. The expression:msg($R{text.message}, $P{number})uses the string referred to by the key text.message as the pattern for the call to msg. The second parameter is the firstargument to be replaced in the pattern string. If text.message is the string “The report contains {0} records.” andthe value for the report parameter number is 100, UR displays the interpreted text string as:The report contains 100 records.327

<strong>iReport</strong> <strong>Ultimate</strong> <strong>Guide</strong>Figure 17-4The resource bundle in the Favorites viewThe bundle node in Favorites provides several tool features. Right-click the file node to open one of the editing tools for theresource bundle:• Edit. Opens a resource bundle as a text file (see Figure 17-3)• Open. Opens the visual resource bundle editor that shows at the same time the translations for all the language you aresupporting (see Figure 17-5).Figure 17-5Visual Bundle EditorTo add a new locale (meaning support for a new language), right-click the resource bundle node and select the menu item Addlocale.... This will pop up the window shown in Figure 17-6. It is used to set the correct language specifications (language,country and optionally a variant code).326

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!