Create a report in the language of the recipient
In addition to considering the language of the user who is running the report, you should also consider the language of the recipient. For example, if you are running a Sales Invoice report, and it doesn't need to be generated in the language of the user who's running the report, you would instead generate it in the language of the person (or company) to whom you're sending the report.
In the case of the Sales Invoice report, and many other document reports, this language will likely be of the customer on the document. This language might be different, depending on the customer. Therefore, if you print multiple invoices at once, then the report needs to change its language, depending on the record that is currently retrieved in the dataset. The report needs to generate a multilingual dataset.
For this reason, in this case, you can't use IncludeCaption or the Labels section because labels are fixed and can't be changed during dataset generation. Instead, you need to manually add table and field captions in the dataset and then add labels as variables inside the dataset.
This technique increases the size of the dataset because, for each field that needs to be multilingual, a field is added to the dataset. The dataset consists of more columns, so this factor might have an impact on the performance of the report.
The available methods to help you generate a multilingual dataset are:
FieldCaption() - Gets the current caption of the specified field as a string.
Caption := Record.FieldCaption(Field: Any);
TableCaption() - Gets the current caption of a table as a string.
Caption := Record.TableCaption();
To declare a label as a variable, you can use the following syntax:
var
a: Label 'Label Text', Comment = 'Foo', MaxLength = 999, Locked = true;
The Label data type is used in .XLF files for translations.
Typically, in a document report, the following code shows in the OnAfterGetRecord() trigger in the header table:
CurrReport.Language := Language.GetLanguageIdOrDefault("Language Code");
The header table should include the Language Code field, which contains the language code of the recipient of the document. The GetLanguageIdOrDefault() function gets the language ID based on its code, or it defaults to the current user language.
The CurrReport.Language() method gets or sets the current language setting for the report.
Review the following example of a report that generates a list of customers. The report has the following syntax:
report 50107 CustomerListLangRecReport
{
UsageCategory = ReportsAndAnalysis;
ApplicationArea = All;
Caption = 'Customer List Report Language Recipient';
AdditionalSearchTerms = 'Customer List Report Language Recipient';
RDLCLayout = 'CustomerListReportLangRep.rdl';
WordLayout = 'CustomerListReportLangRep.docx';
DefaultLayout = RDLC;
dataset
{
dataitem(Customer; Customer)
{
column(CustomerNo; "No.")
{
}
column(CustomerNoCptn; fieldcaption("No."))
{
}
column(CustomerName; Name)
{
}
column(CustomerNameCptn; fieldcaption(Name))
{
}
column(CustomerLanguageCode; "Language Code")
{
}
column(CustomerLanguageCodeCptn; fieldcaption("Language Code"))
{
}
column(City; City)
{
}
column(CityCptn; fieldcaption(City))
{
}
column(BalanceLCY; "Balance (LCY)")
{
}
column(BalanceLCYCptn; fieldcaption("Balance (LCY)"))
{
}
trigger OnAfterGetRecord()
begin
CurrReport.Language := Language.GetLanguageIdOrDefault("Language Code");
end;
}
}
var
Language: Codeunit Language;
ReportTitle: Label 'Report Title', Comment = 'Foo', MaxLength = 999, Locked = true;
}
After retrieving the customer record from the Customer table, the report verifies the language code of the customer and then uses it to set the language of the report. This action changes the result of the fieldcaption function. In the dataset fields, separate columns have been added for the captions.
The layout of the report should resemble the following image.
In the layout of the report, in the header, expressions are used to fetch the Cptn values. The detail rows show that you are fetching the normal values. To make sure that you can group customers by number, the table has been put into a list container.
When you run the report, it looks similar to the following sample.