Skip to main content
Version: v12.1

Translation Context

The translation context is responsible for passing a context to the ElementTranslationService, this includes fields to be translated, glossaries to be used etc. If such a translation context has no values set, it will use the default values of the corresponding translation configuration.

Different Types

Object

The ObjectTranslationContextDto is used as the translation context for objects. For example, it can be used to pass localized fields, brick fields and other translatable content.

NameWert
ClassTwocream\DeepLBundle\Dto\ObjectTranslationContextDto
Constructorpublic function __construct(?array $localizedFields = null, ?array $blockFields = null, ?array $bricks = null, ?array $fieldCollections = null, ?array $objectRelations = null, ?array $glossaries = null)
Optional
$localizedFieldsContains the format for the localized fields that should be translated.
$blockFieldsContains the format for the block fields that should be translated.
$bricksContains the format for the brick fields that should be translated.
$fieldCollectionsContains the format for the field collection fields that should be translated.
$objectRelationsContains the format for the object relations that should be translated.
$glossariesContains the glossaries.

Asset

The AssetTranslationContextDto is used as the translation context for assets. For example, it can be used to pass metadata fields.

NameWert
ClassTwocream\DeepLBundle\Dto\AssetTranslationContextDto
Constructorpublic function __construct(?array $metadataFields = null, ?array $glossaries = null)
Optional
$metadataFieldsContains the names of the "predefined asset metadata" from Pimcore that should be translated.
$glossariesContains the glossaries.

Creation

info

In dem Beispiel werden die Felder aus der Konfiguration entnommen. Sind keine Werte gesetzt, werden normalerweise immer die Felder aus der Konfiguration verwendet. Dies stellt ein Beispiel dar.

In the following example, the fields from the configuration are fetched. If no values are set, the values from the configuration are usually used. This is

$config = TranslationConfigurationLoader::getConfiguration($object->getClassName());

$translationContext = new ObjectTranslationContextDto();
$translationContext->setLocalizedFields($config['fields'] ?? []);
$translationContext->setFieldCollections($config['fieldCollections'] ?? []);
$translationContext->setBricks($config['bricks'] ?? []);
$translationContext->setObjectRelations($config['relations'] ?? []);
$translationContext->setBlockFields($config['blocks'] ?? []);
$translationContext->setGlossaries($config['glossaries'] ?? []);