[Vuejs]-Problem with Utility Functions in Shopware 6

1👍

Please see the documentation on how to add snippets in the administration. You can use the Vue I18n plugin to translate snippets to the currently selected language automatically.

this.$tc('swag-example.general.myCustomText')
// in the template: {{ $tc('swag-example.general.myCustomText') }}

The functions of the plugin are globally available in components. No need to use additional helpers.

For snippet entities you could inject the snippetSetService to fetch the translations by their key.

Component.register('my-component', {
    template,

    inject: [
        'snippetSetService',
    ],

    methods: {
        async getSnippetTranslations(translationKey) {
            this.isLoading = true;

            const translations = await this.snippetSetService.getCustomList(1, 25, { translationKey });

            if (translations.total < 1) {
                return [];
            }

            return translations.data[translationKey];
        },
    },
});

Leave a comment