GlobalLanguage() must be implemented through the Translation Helper codeunit

Properties
AC0005 Info Design Code Fix Ignore Obsolete

Calling GlobalLanguage() with a parameter changes the language for the current session. All subsequent text evaluation — captions, format strings, error messages — uses the new language until it is changed back. Direct callers must save the current language before setting a new one and restore it afterward. If the restore step is missed or an error interrupts execution, the session continues in the wrong language for every operation that follows.

The Translation Helper codeunit eliminates this manual state management. It preserves the current language automatically when you set a new one, exposes RestoreGlobalLanguage() to return to the previous state, and provides SetGlobalLanguageToDefault() to resolve the default application language at runtime instead of hardcoding values like 1033.

Example

The following code manually saves and restores GlobalLanguage:

codeunit 50100 "Document Processing"
{
    local procedure SetDocumentLanguage(LanguageCode: Code[10])
    var
        Language: Codeunit Language;
        CurrentGlobalLanguageId: Integer;
        LanguageId: Integer;
    begin
        CurrentGlobalLanguageId := GlobalLanguage();
        LanguageId := Language.GetLanguageId(LanguageCode);
        GlobalLanguage(LanguageId); // GlobalLanguage() must be implemented through the Translation Helper codeunit [AC0005]
        // Generate document in target language
        GlobalLanguage(CurrentGlobalLanguageId);
    end;
}

To fix this, use the Translation Helper codeunit:

codeunit 50100 "Document Processing"
{
    local procedure SetDocumentLanguage(LanguageCode: Code[10])
    var
        TranslationHelper: Codeunit "Translation Helper";
    begin
        TranslationHelper.SetGlobalLanguageByCode(LanguageCode);
        // Generate document in target language
        TranslationHelper.RestoreGlobalLanguage();
    end;
}

When the diagnostic is reported

  • A call to GlobalLanguage() with a parameter: GlobalLanguage(LanguageId).
  • An assignment to GlobalLanguage: GlobalLanguage := LanguageId.

Reading the current language with GlobalLanguage() does not trigger the diagnostic.

Exception

Reading GlobalLanguage() without a parameter to retrieve the current language ID is valid and does not trigger the diagnostic. A common case is setting the report language to the user’s current session language:

trigger OnPreReport()
begin
    CurrReport.Language := GlobalLanguage();
end;

Alternatively, use the Language codeunit to resolve the language from a record field:

trigger OnPreReport()
var
    Language: Codeunit Language;
begin
    CurrReport.Language := Language.GetLanguageIdOrDefault(Rec."Language Code");
end;

Code fix

The code fix replaces individual GlobalLanguage() calls with the corresponding Translation Helper method:

  • GlobalLanguage(1033) becomes TranslationHelper.SetGlobalLanguageToDefault(), since 1033 is the default application language.
  • GlobalLanguage(<other id>) and GlobalLanguage := <id> become TranslationHelper.SetGlobalLanguageById(<id>).

See also