Skip to main content
Administrator Guide
Last Updated: 2023-06-23
Conditionalize Label Translation with JavaScript

Conditionalize Label Translation with JavaScript

Create a report design file and the resource files that enable the translation of its labels.
You can use an
onCreate
JavaScript to override the translation context on a report design. This enables Report Designer to translate label text based on a specified condition, rather than the language preference of the user running the print task.
  1. To add an
    onCreate
    script, select a label on the
    Layout
    tab of your report design, then select the
    Script
    tab.
  2. From the
    Script
    drop-down list, select
    onCreate
    .
  3. In the text pane, add the appropriate JavaScript.
This example overrides the default language and provides appropriate translation if the locale is fr_CA:
importPackage(Packages.java.util); if(row["Locale"]=="fr_CA") { var lc = new Locale("fr_CA"); this.text = reportContext.getMessage("Dear", lc);}