Schema本地文件

Schema本地文件本地化文件是以 .schema.json 文件为扩展名的 JSON 文件。它们包含各种设置Schema属性的翻译字符串,以便将主题编辑器中的内容翻译为商店的活动语言。

位置

Schema本地文件位于主题的 locales 目录中:

└── theme
    ...
    ├── config
    └── locales
      ├── en.default.schema.json
      ├── es-ES.schema.json
      ...

Schema

Schema本地化文件需要遵循特定的命名结构。它们还遵循基本的组织结构:

  • 类别: 翻译的顶级类别。
  • 组: 类别内翻译的二级分组。
  • 描述: 第三级,表示单个翻译。
{
  "my_category": {
    "my_group": {
      "my_description": "translation text",
      ...
    },
    ...
  },
  ...
}

提示
在命名翻译描述时,尽量使用足够的描述性文字,例如,blogs.article_comment.submit_button_text 就比 blogs.article_comment.submit 要好。

名称结构

本地文件命名必须遵循标准的 IETF 语言标记命名法,其中第一个小写字母代码代表语言,第二个大写字母代码代表地区。
例如

LanguageFormat
English – Great Britainen-GB.schema.json
Spanish – Spaines-ES.schema.json
French – Canadafr-CA.schema.json

如果语言不针对特定地区,可以使用 2 个字母的小写语言表示法。
例如

LanguageFormat
Finnish – All regionsfi.schema.json

此外,您还必须指定一个默认本地化文件。

默认本地化文件

您必须指定一个默认本地化文件,格式为 *.default.schema.json,其中 * 是您选择的语言。该文件包含主题默认语言的翻译。只允许使用一个默认文件。

大多数主题使用 en.default.schema.json,将主题的默认语言设置为英语。

内容

schema本地化文件允许您为以下设置属性创建翻译:

ParentAttribute
All settingsinfo label
settings_schema.json
Section schema
block
name
selectgroup
html
number
text
textarea
video_url
placeholder
rangeunit
header
paragraph
content
presetsname
category

应用

在使用schema本地化文件时,应熟悉schema翻译的引用。

引用schema翻译

可使用以下格式的代码访问Schema翻译:

t:translation_category.translation_group.translation_name

例如,要使 product.liquid分区的 name 属性可翻译,请使用下面的方法:

locales/en.default.schema.json

{
  "sections": {
    "product": {
      "name": "Product"
    }
  }
}

sections/product.liquid

{% schema %}
{
  "name": "t:sections.product.name",
  ...
}
{% endschema %}

原文:https://shopify.dev/docs/themes/architecture/locales/schema-locale-files

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注