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.
| Name | Wert |
|---|---|
| Class | Twocream\DeepLBundle\Dto\ObjectTranslationContextDto |
| Constructor | public function __construct(?array $localizedFields = null, ?array $blockFields = null, ?array $bricks = null, ?array $fieldCollections = null, ?array $objectRelations = null, ?array $glossaries = null) |
| Optional | |
$localizedFields | Contains the format for the localized fields that should be translated. |
$blockFields | Contains the format for the block fields that should be translated. |
$bricks | Contains the format for the brick fields that should be translated. |
$fieldCollections | Contains the format for the field collection fields that should be translated. |
$objectRelations | Contains the format for the object relations that should be translated. |
$glossaries | Contains the glossaries. |
Asset
The AssetTranslationContextDto is used as the translation context for assets. For example, it can be used to pass metadata fields.
| Name | Wert |
|---|---|
| Class | Twocream\DeepLBundle\Dto\AssetTranslationContextDto |
| Constructor | public function __construct(?array $metadataFields = null, ?array $glossaries = null) |
| Optional | |
$metadataFields | Contains the names of the "predefined asset metadata" from Pimcore that should be translated. |
$glossaries | Contains the glossaries. |
Creation
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'] ?? []);