TranslationService
  • 26 Nov 2024
  • 1 Minute to read
  • Dark
    Light

TranslationService

  • Dark
    Light

Article summary

To be able to retrieve record text field translations registered by OrderCentral you can use the welisacommerce.TranslationService class. It holds a method getLocalizedRecords(). It accepts an instance of the welisacommerce.TranslationService GetLocalizedRecordsRequest. It returns an instance of welisacommerce.TranslationService .GetLocalizedRecordsResult.

Class definitions

All classes that are used as input and output are listed below


welisacommerce.TranslationService.GetLocalizedRecordsRequest

Property NameProperty TypeDescription
recordIdsList<Id>Ids of the records to retrieve. All need to be of the same type
fieldsList<Schema.SObjectField>The field tokens which needs to be translated
languagesList<String>The language iso codes which translate the values to (examples: nl_NL, en_US)
onlyIncludeTranslatedRecordsBooleanIf true only records will be returned that are translated, defaults to false

welisacommerce.TranslationService .GetLocalizedRecordsResult

Property NameProperty TypeDescription
resultsList<welisacommerce.TranslationService .LocalizedRecords>A list of localized records grouped by language iso code

welisacommerce.TranslationService.LocalizedRecords

Property NameProperty TypeDescription
languageStringThe language iso code to which the records are translated
recordsList<welisacommerce.LocalizedSObjectDto>A list of translated records

welisacommerce.LocalizedSObjectDto

Property NameProperty TypeDescription
recordIdIdThe language iso code to which the records are translated
fieldsMap<String, welisacommerce.LocalizedFieldValueDto>Hold the translated field value by the field api name

welisacommerce.LocalizedFieldValueDto

Property NameProperty TypeDescription
valueObjectThe actual field value
displayValueStringThe localized (translated) field value

Example class

public class ExampleClass {
    public List<welisacommerce.LocalizedSObjectDto> getTranslatedRecords(List<Id> webProductIds) {
            welisacommerce.TranslationService.GetLocalizedRecordsRequest request = 
                new welisacommerce.TranslationService.GetLocalizedRecordsRequest();

            request.recordIds = webProductIds; 
            request.fields = new List<Schema.SObjectField> { 
                welisacommerce__Web_Product__c.welisacommerce__Title__c 
            };
            request.languages = new List<String>{ 'nl_NL' };
            request.onlyIncludeTranslatedRecords = true;

            return welisacommerce.TranslationService.getLocalizedRecords(request).results);
    }
}