Skip to main content

Translatable Entity-Creation

You can add a configuration field to your Entity Creation section to make Entities translatable. It is necessary to follow this Guide for this first.

Step 1

In your detail page's index.js, first import StateDeprecated. const { StateDeprecated } = Shopware;

Then, add a method in the computed section of the index class to fetch the language object:

computed: {
languages() {
return StateDeprecated.getStore('language')
}
},

Then, set the language in the created method:

created() {
this.setLanguage();
}

And define the method:

setLanguage() {
if(this.entity && Shopware.Context.api.languageId !== this.languages.systemLanguageId) {
Shopware.State.commit('context/setApiLanguageId', this.languages.systemLanguageId);
}
}

First, check if the entity exists. This prevents loading when something went wrong with fetching the Entity. Then check, if the current language isn't already the System Language.

Step 2

Head over to your detail .twig file. Add this Code for a Language Switch. Add it in between your #smart-bar-actions and your #content <template>-tags.

<template #language-switch>
<sw-language-switch slot="language-switch"></sw-language-switch>
</template>

The isCreate Property is something you have to set in the create-page's created() method. this.isCreate = true; is enough.