Report Translation

PeopleTools enables you to print or format SQR output for multiple languages using string definitions that are stored in the Strings table. The procedures defined in SQRTRANS.SQC enable your SQR program to access these strings dynamically.

To enable the use of the Strings table in your SQR program, you must include the PeopleTools SQC file SQRTRANS.SQC, which includes the routines that are necessary to initialize and load translated strings from the Strings table.

SQRTRANS.SQC has four main functions that you can call from the report:

  • Init_Report_Translation

  • Get_Field_Information

  • Append_Report_Translation

  • Add_Report_Translation

Init_Report_Translation

Call the Init_Report_Translation procedure from your SQR program before using any of the String table information. Typically, you should call Init_Report_Translation in the Init-Report section of your SQR program. Init_Report_Translation takes two parameters:

Parameter Name Description

$Report_ID

$Report_ID is normally the name of the SQR report. This parameter is used as the program ID when looking up strings in the Strings table.

$Report_Language

$Report_Language indicates the preferred language for the strings that are being retrieved. Init_Report_Translation attempts to load all strings in the language specified; however, if a translation for any string does not exist, it loads the base language description for that string.

If you want to change languages during the processing of an SQR report (for example, if you want each page of the report to be in a different language), you can call Init_Report_Translation multiple times within a single SQR program, each time passing a new $Report_Language value.

Get_Field_Information

Call the Get_Field_Information procedure for each string that you want to retrieve from the Strings table. It retrieves the label or string table entry for the field specified and places it in a report variable. You can then print the contents of this variable on your report as a label, column heading, or free text. Get_Field_Information takes four parameters:

Parameter Name Description

$Report_ID

$Report_ID is normally the name of your SQR report. This parameter is used as the program ID when looking up strings in the Strings table. You must have already called Init_Report_Translation specifying this $Report_ID before passing it to Get_Field_Information.

$Field_ID

This is the string ID of the string whose text you want to retrieve. It must exist as an entry in the Strings table under the $Report_ID that you specified.

$Field_Text

$Field_Text is the output variable. Get_Field_Information populates this variable with the text that corresponds to the $Report_ID and $Field_ID that are specified in the preferred language or in the database’s base language (if a translation doesn’t exist in the preferred language).

$Field_Width

$Field_Width is an output variable that Get_Field_Information populates with the width of the text string that is returned.

Append_Report_Translation

If your SQR program uses strings from more than one Strings table program ID, call Append_Report_Translation to add the strings from another program ID to the initialization array created by Init_Report_Translation. This function is particularly useful if you have a set of strings that is used across many of your SQR programs. You can group these strings under a generic program ID and use them in multiple SQR programs.

Append_Report_Translation takes a single argument, $Report_ID. It assumes the same language that was specified in Init_Report_Translation. It must be called after Init_Report_Translation.

Add_Report_Translation

The Add_Report_Translation procedure calls Init_Report_Translation or Append_Report_Translation, depending on whether the Strings table has been initialized. It takes the same arguments as Init_Report_Translation. If Init_Report_Translation has not yet been called during the processing of this SQR program, this function calls it, passing both parameters. If Init_Report_Translation has already been called, Add_Report_Translation calls Append_Report_Translation, passing only the $Report_ID parameter.

This function is useful in your own SQC files if you cannot be certain that the calling SQR program has already initialized the Strings table. The function ensures that the table is initialized or appended correctly.

Sample Strings Table Enabled SQR Program

The following sample code demonstrates how to use the Strings table to retrieve string values in SQR, using the procedures described in the preceding sections.

!************************************************
!  SAMP001:  Report on database's base language *
!************************************************
#include 'setenv.sqc'    !Set environment
begin-report
  do Init-Report
  do Process-Main
  do Reset
end-report
begin-heading 6
do Get_Field_Information ('SAMP001',    'REPORT_TITLE', $REPORTTITLE,   #DWRT)
do Get_Field_Information ('SAMP001',    'EXPLAIN_TEXT', $EXPTEXT,       #DWET)
PRINT $REPORTTITLE       (1)    CENTER
PRINT $EXPTEXT           (+2,1)
end-heading
begin-procedure Init-Report
move 'SAMP001' to $ReportID
move 'ENG' to $Language_cd
do Init_Report_Translation ($ReportID, $Language_cd)
do Append_Report_Translation ('GEN')
end-procedure
begin-procedure Process-Main
do Get_Field_Information ('GEN',        'BASELANGUAGE', $BASELANGUAGE,  #DWBL)
do Get_Field_Information ('GEN',        'ENDOFREPORT',  $ENDOFREPORT,   #DWER)
begin-SELECT 
LANGUAGE_CD &Base_Language
   let $langlabel = $BASELANGUAGE || ':'
   print $langlabel  (+1,1)
   let #fieldpos = #DWBL + 3
   print &Base_Language (0,#fieldpos)
FROM PSOPTIONS
end-SELECT
print $ENDOFREPORT      (+4,1)
end-procedure
#Include 'reset.sqc'     !Reset printer procedure
#Include 'sqrtrans.sqc'  !SQR Strings Table procedures