【问题标题】:How i use the English translation as fallback in plugin ( Shopware 6 )我如何使用英文翻译作为插件的后备(Shopware 6)
【发布时间】:2021-03-15 11:02:27
【问题描述】:

您好,我尝试在 Shopware 商店中发布插件。在查看我的插件后,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

后备语言 安装并不总是使用英语或德语。 因此,请确保您的扩展程序也适用于其他语言。一个 示例:客户有他的西班牙语安装,您的分机 尚无此语言版本。所以你应该使用英文 翻译作为后备。

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

更新

之前,我在service.yml中定义了sn-p文件,没有优先选项

<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文件。是否可能与此错误有关。例如,用户可以在config插件中选择默认语言??

【问题讨论】:

    标签: shopware


    【解决方案1】:

    更好的解决方案应该是:

    use Shopware\Core\Defaults;
    
    ...
    
    'label' => [
         'en-GB' => 'my english label',
         'de-DE' => 'meine deutsche Beschriftung',
         Defaults::LANGUAGE_SYSTEM => 'my default language label',
    ]
    
    ...
    

    最好的问候

    塞巴斯蒂安

    【讨论】:

      【解决方案2】:

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

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

      如果客户有不同的默认语言,如西班牙语,他/她在安装插件时会出错。

      我应该如下定义后备语言

           /**
           * @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
                          ]
                      ],
                      .
                      .
                      .
      

      【讨论】:

        猜你喜欢
        • 2021-08-01
        • 2020-11-25
        • 2020-04-03
        • 2022-12-17
        • 2017-05-24
        • 2018-08-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多