是否允许在主题中添加带有自定义键翻译的片段,还是仅允许 Shopware 6 中的插件? 例如:
shopware6/custom/plugins/MyCustomTheme/src/Resources/snippet/en_GB/customtheme.en-GB.json
{
"customtheme": {
"footer": {
"someNewKey": "Some value"
}
}
}
是的,允许在 Shopware 6 的主题中添加带有自定义键的片段以进行翻译。但是,建议遵循指定的模式:
按照模式
<name>.<locale>
命名片段文件。
<name>
:您可以自由定义名称。<locale>
:区域设置必须与代码片段文件中支持的区域设置的 ISO 字符串相对应。用你的例子:
customtheme.en-GB.json
让我们检查一下结果:
└── 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
customtheme.en-GB.json
.{
"customtheme": {
"footer": {
"someNewKey": "Some value"
}
}
}
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 %}