Skip to content

[BC Idea]: Add GetTranslations Method to Translation Codeunit for Bulk Translation Retrieval for a Specific Table and Field #5434

@diveshbora

Description

@diveshbora

BC Idea Link

https://experience.dynamics.com/ideas/idea/?ideaid=1b910a92-feba-f011-aa43-7c1e52f5eb6b

Description

Description

We are developing multilingual functionality for our Business Central extension and found that there are existing APIs for handling translations in the System Application. There is a need to copy translations from master data records (stored in the Translation table) to BC standard translation tables (e.g., Item Translation table) when creating records from templates.

Current Limitation: The Translation table (Table 3712) has Access = Internal, making it inaccessible to extension developers. The Translation codeunit (Codeunit 3711) only provides individual translation operations (Get, Set, Delete, Show) but lacks a method to retrieve ALL the translations for a given record/field, which is essential for copying translations from the Translation table to BC standard translation tables like Item Translation.

Request: Add a new public API method to the Translation codeunit to retrieve all translations for a given record/field in a consumable format (Buffer Table or Dictionary).

New Table - "Translation Buffer"

table 3713 "Translation Buffer"  // table number needs to be verified
{    
    Access = Public;
    Caption = 'Translation Buffer';
    InherentEntitlements = X;
    InherentPermissions = X;
    TableType = Temporary;
       
    fields
    {      
        field(1; "Language ID"; Integer)
        {
            DataClassification = SystemMetadata;
            Caption = 'Language ID';
            TableRelation = Language."Windows Language ID";
        }
        field(2; "System ID"; Guid)
        {
            DataClassification = SystemMetadata;
            Caption = 'System ID';
            Editable = false;
        }
        field(3; "Table ID"; Integer)
        {
            DataClassification = SystemMetadata;
            Caption = 'Table ID';
            Editable = false;
        }
        field(4; "Field ID"; Integer)
        {
            DataClassification = SystemMetadata;
            Caption = 'Field ID';
            Editable = false;
        }
        field(5; Value; Text[2048])
        {
            DataClassification = CustomerContent;
            Caption = 'Value';
        }
    }
    
    keys
    {
        key(Key1; "Language ID", "System ID", "Field ID")
        {
            Clustered = true;
        }
    }
}

Public API: New Procedure in codeunit 3711 Translation

/// <summary>
/// Gets all available translations for a specific record field as a temporary buffer
/// </summary>
/// <param name="RecVariant">Source record variant</param>
/// <param name="FieldId">Field ID to get translations for</param>
/// <param name="TranslationBuffer">Output: Temporary buffer with translations</param>
/// <returns>True if translations were found</returns>
procedure GetTranslations(RecVariant: Variant; FieldId: Integer; var TranslationBuffer: Record "Translation Buffer"): Boolean
begin
    exit(TranslationImplementation.GetTranslations(RecVariant, FieldId, TranslationBuffer));
end;

Implementation: New Procedure in codeunit 3712 "Translation Implementation"

procedure GetTranslations(RecVariant: Variant; FieldId: Integer; var TranslationBuffer: Record "Translation Buffer"): Boolean
var
    Translation: Record Translation;
    FromRecordRef: RecordRef;
begin
    TranslationBuffer.Reset();
    TranslationBuffer.DeleteAll();

    GetRecordRefFromVariant(RecVariant, FromRecordRef);    
    Translation.SetRange("System ID", GetSystemIdFromRecordRef(FromRecordRef));
    Translation.SetRange("Table ID", FromRecordRef.Number());
    if FieldId <> 0 then
        Translation.SetRange("Field ID", FieldId);    
    if Translation.FindSet() then
        repeat
            TranslationBuffer.Init();
            TranslationBuffer.TransferFields(Translation);
            TranslationBuffer.Insert();
        until Translation.Next() = 0;
    
    exit(TranslationBuffer.FindFirst());
end;

I will provide the implementation for this BC Idea

  • I will provide the implementation for this BC Idea
    Internal work item: AB#613845

Metadata

Metadata

Assignees

No one assigned

    Labels

    ApprovedThe issue is approvedBCIdeaIssue related to a BCIdeaIntegrationGitHub request for Integration areaLinkedIssue is linked to a Azure Boards work item

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions