首頁  >  問答  >  主體

Shopware 6中的功能實用性疑問

我現在在專案中的一個節點上,希望使用helpers,並且已經看了這個連結:

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

我想要一個幫助器,用於翻譯從資料庫中讀取的片段,也許還有一些其他的功能,以使專案更加可管理(也許有更簡單的方法,我需要使用相當多的函數來進行翻譯)。

正如文章所說,我也看了Shopware對象,但是我不知道如何使用這個物件來存取一個函數。

謝謝幫忙。 ###
P粉852114752P粉852114752407 天前539

全部回覆(1)我來回復

  • P粉463824410

    P粉4638244102023-09-09 08:07:10

    請參閱關於如何在管理介面中新增片段的文件。您可以使用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];
            },
        },
    });
    

    回覆
    0
  • 取消回覆