Questions about functionality in Shopware 6
P粉852114752
P粉852114752 2023-09-08 09:49:30
0
1
407

I am currently on a node in the project and wish to use helpers, and have looked at this link:

https://developer.shopware.com/docs/guides/plugins/plugins/administration/using-utils

I would like a helper for translating fragments read from the database and maybe some other functionality to make the project more manageable (maybe there is an easier way, I need to use quite a few functions to translate).

As the article said, I also looked at the Shopware object, but I don't know how to use this object to access a function.

Thanks for the help.

P粉852114752
P粉852114752

reply all(1)
P粉463824410

See the documentation on How to add fragments in the admin interface. You can use the Vue I18n plugin to automatically translate snippets into the currently selected language.

this.$tc('swag-example.general.myCustomText')
// 在模板中:{{ $tc('swag-example.general.myCustomText') }}

The functions of this plug-in are globally available in the component without using additional auxiliary functions.

For snippet entities, you can inject snippetSetService to get the translation by its 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];
        },
    },
});
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!