Previous Page Next Page
Built-in Functions for NLS
Two built-in Translate functions are available in formulas for applying the NLS feature to the formula result.
- Translate(String a)
This function searches for the NLS translation of the current field values in the bound data mapping file.
- Translate(String a, String b)
This function accesses the corresponding data mapping file dynamically according to the language selected from the language drop-down list on the NLS language toolbar and searches for the NLS translation of String b in it.
The following example shows the usage of the two functions. It is based on the page report List of Customer Contact Cards.cls in the SampleReports.cat catalog file.
- Open the page report List of Customer Contact Cards.cls in the catalog SampleReports.cat saved in
<install_root>\Demo\Reports\SampleReports
.
- Preview the report and it displays as follows:

- Click the Design tab to return to the design mode.
- Click View > Language > NLS Editor.
- In the NLS Editor, click
above the Language box.
- In the Add Language dialog, select Chinese (China) from the Available Languages list and click OK to add it to the Language box of the NLS Editor.

- Click OK in the NLS Editor.
- Open the Catalog Manager and click Data Mapping Editor on its toolbar.
- In the Data Mapping Editor, click the New button.
- 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.

- Click the Import Key button, select the fields City and State in the Customers table of the displayed dialog and click OK.

- Double-click cells in the Map to Value column to specify the mapping values for the imported resources in Chinese. Click OK.
- Expand Data Source 1 > jdbc connection > Tables > Customers node in the Catalog Manager, select the City column, click the Show Properties button to expand the Properties sheet 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 Manager can be changed.
- Repeat the step above to set the Data Mapping File property of the column State in the same table to DataMapping.
- Click Save Catalog on the Catalog Manager toolbar to save the changes.
- Right-click the formula field CustomerCityStateZip in the report and select Edit Formula from the shortcut menu. The formula is written as below in the Formula Editor:

- Edit the formula to Translate(@City) + ", " + Translate(@State) + " " + Translate(@"Postal Code"), then click Save on the toolbar to save the formula. Close the Formula Editor.

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.
- 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 File > Save to save the report.
- Click View > Language > Chinese (China).
- Preview the report and you can find the formula result is displayed in Chinese:

Notes:
- When either of the two functions is called in a formula, you are suggested not to use the formula to do further calculation unless you can make sure it is correct.
- When a formula references a parameter and the parameter's Allow Multiple Values property is true, the two functions are not available in the Formula Editor for editing the formula. In this case, if you want to apply NLS in the formula result, you can bind the data mapping file to the formula directly.
- The two functions can also be called in formulas on JReport Server, but they take effect only when the bound data mapping file exists in JReport Server. Moreover, only when the data mapping file is used in JReport Designer, can it be published to JReport Server together with the object it is bound to.
Previous Page Next Page