是否允许在主题中添加带有自定义键的片段进行翻译?

问题描述 投票:0回答:1

是否允许在主题中添加带有自定义键翻译的片段,还是仅允许 Shopware 6 中的插件? 例如:

shopware6/custom/plugins/MyCustomTheme/src/Resources/snippet/en_GB/customtheme.en-GB.json

{
  "customtheme": {
    "footer": {
      "someNewKey": "Some value"
    }
  }
}
shopware shopware6
1个回答
0
投票

是的,允许在 Shopware 6 的主题中添加带有自定义键的片段以进行翻译。但是,建议遵循指定的模式:

按照模式

<name>.<locale>
命名片段文件。

  • <name>
    :您可以自由定义名称。
  • <locale>
    :区域设置必须与代码片段文件中支持的区域设置的 ISO 字符串相对应。

用你的例子:

customtheme.en-GB.json

更多信息,您可以参考文档。

让我们检查一下结果:

  1. 根据您的示例创建了一个主题。
└── MyCustomTheme
    ├── src
    │   ├── Resources
    │   │   ├── app
    │   │   ├── snippet
    │   │   │   ├── de_DE
    │   │   │   │   └── customtheme.de-DE.json
    │   │   │   └── en_GB
    │   │   │       └── customtheme.en-GB.json
    │   │   ├── views
    │   │   │   └── storefront
    │   │   │       └── layout
    │   │   │           └── footer
    │   │   │               └── footer.html.twig
    │   │   └── theme.json
    │   └── MyCustomTheme.php
    └── composer.json
  1. 文件内容
    customtheme.en-GB.json
    .
{
  "customtheme": {
    "footer": {
      "someNewKey": "Some value"
    }
  }
}
  1. 文件内容
    footer.html.twig
    .
{% sw_extends '@Storefront/storefront/layout/footer/footer.html.twig' %}

{% block layout_footer_copyright %}
    <div class="footer-copyright">
        {% sw_icon 'shopware' style {'size':'xs'} %}

        {{ "customtheme.footer.someNewKey"|trans|sw_sanitize }}
    </div>
{% endblock %}

The result is displayed in the screenshot.

© www.soinside.com 2019 - 2024. All rights reserved.