Shopware 6中的功能实用性疑问
P粉852114752
P粉852114752 2023-09-08 09:49:30
0
1
519

我现在在项目中的一个节点上,希望使用helpers,并且已经看了这个链接:

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

我想要一个帮助器,用于翻译从数据库中读取的片段,也许还有一些其他的功能,以使项目更加可管理(也许有更简单的方法,我需要使用相当多的函数来进行翻译)。

正如文章所说,我也看了Shopware对象,但是我不知道如何使用这个对象来访问一个函数。

谢谢帮助。

P粉852114752
P粉852114752

全部回复(1)
P粉463824410

请参阅关于如何在管理界面中添加片段的文档。您可以使用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];
        },
    },
});
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!