Skip to main content
Version: 2026.10

Handling of Translations

In some cases, it is necessary to export translations and then import them into Shopware.

Pimcore​

The TranslationService is available in Pimcore. It can be obtained in the adapter via the method $this->translationHelper().

Class​

Twocream\ShopwareConnectorBundle\Service\TranslationService

Method mapTranslations​

The method retrieves the values in all available Pimcore languages and returns an array. Field names can be renamed during export to simplify subsequent processing in Shopware.

NameValue
Functionpublic function mapTranslations(Localizedfield $field, array $fieldNames = [], array $map = [], ?string $defaultLanguage = ''): array
Argument $fieldLocalized fields of the object
(Optional) Argument $fieldNamesPimcore field identifier of the field whose values should be exported
(Optional) Argument $mapDefines the name of the target field in the export
(Optional) Argument $defaultLanguageIf a value is missing in a language, it is taken from the specified default language
Return valuesee Output

Example​

protected function prepare($object): array
{
$texts = $this->translationHelper()->mapTranslations(
$object->getLocalizedfields(),
['articleName', 'description'],
['articleName' => 'name']
);

return [
// ...,
'translations' => $texts ?? [],
// ...,
];
}

Output​

With the language mapping de: de_DE and en: en_GB:

[
'de_DE' => [
'name' => 'Example Name',
'description' => 'Example Description'
],
'en_GB' => [
'name' => 'Example Name',
'description' => 'Example Description'
]
]

Method getSupportedLanguageMapping​

The method returns getLanguageMapping() restricted to the passed Pimcore languages. With an empty array, it returns the complete getLanguageMapping(). The product export passes the option supported_languages of the export target (see "Configure Language Mapping").

NameValue
Functionpublic function getSupportedLanguageMapping(array $supportedLanguages): array
Parameter$supportedLanguages: Pimcore languages, e.g., ['de', 'en']
Return valuePimcore language => Shopware locale, e.g., ['de' => 'de_DE', 'en' => 'en_GB']

In contrast, getLanguageMapping() – and therefore mapTranslations() – contains all valid and not disabled Pimcore languages, languages without mapping under their Pimcore key. The product export (ProductAdapterAbstract) exports the languages of getSupportedLanguageMapping() (see "Pimcore language and Shopware locale").

Shopware​

In Shopware, the ModuleService is available in every import module via $this->service, e.g., $this->service->prepareTranslation().

Class​

Twocream\JsonImporter\Core\System\Import\Module\Service\ModuleService

Method prepareTranslation​

The method transforms the exported translations into the appropriate Shopware import format. Additionally, optional renaming of fields can be performed via a mapping. The keys of the translations are mapped to the languages in Shopware via JsonImportConfiguration::getLocaleMapping(), e.g. de => de_DE and en => en_GB (see "Which locales are accepted?").

NameValue
Functionpublic function prepareTranslation(array $translations, array $keyMap = []): array
Argument $translationsPassing the translation arrays from export
(Optional) Argument $keyMapMapping of fields: export field to target field. With a mapping only the mapped fields are taken over
Return valueArray

Example​

protected function store(Result $result): ?EntityWrittenContainerEvent
{
// ...

foreach ($result as $entry) {
$records[] = [
'id' => $entry['uuid'],
'translations' => $this->service->prepareTranslation($entry['texts']),
// ...,
];
}

// ...
}