我如何在插件中使用英文翻译作为后备 (Shopware 6)

How i use the English translation as fallback in plugin ( Shopware 6 )

你好,我尝试在 Shopware 中发布一个插件 store.after 检查我的插件,Shopware 向我发送了一个错误。

The plugin cannot be installed. The plugin could not be installed due to the error message "Translation required for system language 2fbb5fe2e29a4d70aa5854ce7ce3e20b" The default language must be selected during installation.

我搜索了一下,找到了这个 document

Fallback language The installation is not always in English or German. So make sure that your extension works in other languages as well. An example: The customer has his installation in Spanish, your extension is not yet available in this language. So you should use the English translation as fallback.

我不知道如何在我的插件中定义默认语言

更新

之前,我在 service.yml 中定义了没有优先选项的片段文件

<service id="MyNamespace\Resources\snippet\en_GB\SnippetFile_en_GB" public="true">
   <tag name="shopware.snippet.file" />
</service>
<service id="MyNamespace\Resources\snippet\de_DE\SnippetFile_de_DE" public="true">
   <tag name="shopware.snippet.file"/>
</service>

现在

<service id="MyNamespace\Resources\snippet\en_GB\SnippetFile_en_GB" public="true">
   <tag name="shopware.snippet.file" priority="100"/>
</service>
<service id="MyNamespace\Resources\snippet\de_DE\SnippetFile_de_DE" public="true">
   <tag name="shopware.snippet.file" priority="100"/>
</service>

PS:我不知道 config.xml file.Is 错误可能与 it.For 示例有关,用户可以 select 默认语言在配置插件中??

在我的插件中,我需要在 custom_field 中插入所需的数据 我使用安装方法。 在那里我只指定了 2 种语言,但这是错误的。

'label' => [
           
             'en-GB' => 'custom field example',
             'de-DE' => 'Beispiel für ein benutzerdefiniertes Feld',
             '2fbb5fe2e29a4d70aa5854ce7ce3e20b' => 'custom field example'
           ]

如果客户使用不同的默认语言,例如西班牙语,he/she 安装插件时会出现错误。

我应该定义 后备语言 如下

     /**
     * @param InstallContext $context
     */
public function install(InstallContext $context): void
    {
     parent::install($context);

 $customFieldSetRepository = $this->container->get('custom_field_set.repository');
   $customFieldSetRepository->create([
            [
                'name' => 'custom_field_example',
                'global' => true,
                'config' => [
                    'label' => [
                         'en-GB' => 'custom field example',
                         'de-DE' => 'Beispiel für ein benutzerdefiniertes Feld',
                         '2fbb5fe2e29a4d70aa5854ce7ce3e20b' => 'custom field example
                    ]
                ],
                .
                .
                .

更好的解决方案应该是:

use Shopware\Core\Defaults;

...

'label' => [
     'en-GB' => 'my english label',
     'de-DE' => 'meine deutsche Beschriftung',
     Defaults::LANGUAGE_SYSTEM => 'my default language label',
]

...

此致

塞巴斯蒂安