问题:Shopware 6中的实用功能存在问题。

huangapple go评论48阅读模式
英文:

Problem with Utility Functions in Shopware 6

问题

我现在在我的项目中的一个阶段,想要使用辅助工具,并查看了以下链接:

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

我想要一个辅助工具,用于翻译从数据库中读取的片段,也许还有一个视图,以使项目更加可管理(也许有更简单的方法,我需要使用不少函数来进行翻译)。

正如文章中所述,我也查看了Shopware对象,但我不知道如何使用这个对象访问函数。

谢谢帮助。

英文:

I am now at a point in my project where I would like to use helpers and have looked at this point:

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

I would like to have a helper that translates my snippets read from the database, and maybe a view more to make the project more overseeable (maybe there is an easier way, I needed quite a few functions to get the translation).

As the article says, I also looked at the Shopware object, but I don't know how I could access a function using this object.

Thanks for helping

答案1

得分: 1

请查看如何在管理界面中添加代码片段的文档。您可以使用Vue I18n插件自动将代码片段翻译为当前选择的语言。

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

插件的功能在组件中是全局可用的,无需使用额外的辅助工具。

对于snippet实体,您可以注入snippetSetService以按其键获取翻译。

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];
        },
    },
});
英文:

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(&#39;swag-example.general.myCustomText&#39;)
// in the template: {{ $tc(&#39;swag-example.general.myCustomText&#39;) }}

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(&#39;my-component&#39;, {
    template,

    inject: [
        &#39;snippetSetService&#39;,
    ],

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

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

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

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

huangapple
  • 本文由 发表于 2023年5月17日 15:02:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/76269335.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定