Using the Built-in Functions for NLS
Logi Report provides two built-in Translate functions for applying the NLS feature to the formula result. This topic introduces the two functions briefly and presents an example to show the usage of the functions.
This topic contains the following sections:
The Translate Functions
You can reference the following Translate functions in formulas to display the formula result in the specified language.
- 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.
Example of Calling the Translate Functions
The following example shows how you can call a Translate function in a formula to display the formula result in Chinese.
- Navigate to Home > Open to open the page report List of Customer Contact Cards.cls in the catalog SampleReports.cat saved in
<install_root>\Demo\Reports\SampleReports
. - Select the View tab to preview the report.
- Select the Design tab to return to design mode.
- Navigate to View > Language > NLS Editor.
- In the NLS Editor dialog box, select Add above the Language box.
- In the Add Language dialog box, select Chinese (China) from the Available Languages list and select OK to add it to the Language box of the NLS Editor dialog box.
- Select OK in the NLS Editor dialog box.
- Open the Catalog Manager and select Data Mapping Editor on its toolbar.
- In the Data Mapping Editor dialog box, select New.
- In the Create Data Mapping File dialog box, type DataMapping in the File Name text box and select Chinese (China) from the Language drop-down list. Select OK to go back to the Data Mapping Editor dialog box.
- Select Import Key.
- In the Import Key dialog box, select the fields City and State in the Customers table and select OK.
- Double-click cells in the Map to Value column to specify the mapping values for the imported resources in Chinese. Select OK.
- Navigate to the Data Source 1 > jdbc connection > Tables > Customers node in the Catalog Manager, select the City column, select Show Properties to expand the Properties sheet on the right, then select DataMapping from the Data Mapping File property value drop-down list.
- Repeat the preceding step to set the Data Mapping File property of the column State in the same table to DataMapping.
- Select Save Catalog on the Catalog Manager toolbar to save the changes.
- Right-click the formula field CustomerCityStateZip in the report and select Edit from the shortcut menu. The formula expression is as follows:
- Edit the formula to
Translate(@City) + ", " + Translate(@State) + " " + Translate(@"Postal Code")
, then select Save on the toolbar to save the formula. Close the Formula Editor dialog box.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 display the Chinese characters completely in the report, next we need to edit the font properties for the formula field CustomerCityStateZip.
- Select the formula CustomerCityStateZip in the report again, then set its Font Face property to SimSun and Font Size property to 12 in the Report Inspector.
- Save the report.
- Navigate to View > Language > Chinese (China).
- Preview the report again. Designer displays the formula result in Chinese.
- When you call either of the two Translate functions 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 dialog box 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.
- You can also call the two functions in formulas on Server, but they take effect only when the bound data mapping file exists on Server. Moreover, only when you have applied the data mapping file in Designer, can you publish it to Server together with the object it is bound to.