Built-in functions for NLS

Two built-in functions are added in formulas for applying the NLS feature to the formula result.

Notes:

Example of calling the functions in a formula

The following example is based on the report CustomerContactCard.cls in the SampleReports.cat catalog file.

  1. In JReport Designer, click File > Catalog Management > Open Catalog on the menu bar to bring out the Open Catalog File dialog.
  2. Browse to select the SampleReports.cat catalog file in <install_root>\Demo\Reports\SampleReports, click the Open button, and then click Yes in the Warning dialog.
  3. Click File > Open. In the Open Report dialog, select CustomerContactCard.cls from the Reports tab and click the Open button to open the report.
  4. Preview the report and it displays as follows:

  5. Click the Design tab to return to the design mode.
  6. Click Edit > NLS Editor. The NLS Editor appears.
  7. In the NLS Editor, click  above the Language box, then in the Add Language dialog, select Chinese (China) from the Available Languages list and click OK to add it and return to the NLS Editor. Click OK in the NLS Editor.
  8. Click  on the Catalog Browser toolbar. The Data Mapping Editor apears.
  9. Click the New button, then in the Create Data Mapping File dialog, input DataMapping in the File Name text field and select Chinese (China) from the Language drop-down list. Click OK to go back to the Data Mapping Editor.
  10. Click the Import Key button, select the fields City and State in the Customers table of the displayed dialog and click OK.
  11. Double-click cells in the Map to Value column to specify the mapping values for the imported resources in Chinese. Click OK.
  12. Expand Data Source 1 > JDBC Connection > Tables > Customers node in the Catalog Browser, select the City column, expand the Properties panel on the left, then select DataMapping from the Data Mapping File property value drop-down list.

    Make sure that the option Forbid editing data object properties in the Catalog category of the Options dialog is unchecked so that the object property values in the Catalog Browser can be changed.

  13. Repeat the step above to set the Data Mapping File property of the column State in the same table to DataMapping. Click  on the Catalog Browser toolbar to save the changes.
  14. Right-click the formula field CustomerCityStateZip in the report and select Edit Formula from the shortcut menu to bring out the Formula Editor. The formula is written as below:

  15. Edit the formula to Translate(@City) + ", " + Translate(@State) + "  " + Translate(@"Postal Code"), then click  on the toolbar to save the formula. Click File > Close to close the window.

    If you have not set the data mapping file of the table columns, you can also edit the formula as follows to apply the NLS feature: Translate("DataMapping", @City)+ ", " +Translate("DataMapping", @State) + "  " + Translate("DataMapping", @"Postal Code").

To make the Chinese characters displayed completely in the report, next we need to edit the font properties for the formula field CustomerCityStateZip.

  1. Select the formula CustomerCityStateZip in the report, then set its Font Face property to SimSun and Font Size property to 12 in the Report Inspector. Click  on the JReport Designer toolbar to save the report.
  2. Select Chinese (China) from the language drop-down list on the NLS language toolbar.
  3. Preview the report and you can find the formula result is displayed in Chinese: