Schema locale 文件
Schema locale 文件是扩展名为 .schema.json
的 JSON 文件。它们包含各种设置 schema 属性的翻译字符串,用于让主题编辑器中的内容可以翻译成商店的 当前语言。
想了解哪些属性可以被翻译,请参考 Content。
位置
Schema locale 文件位于主题的 locales
目录中:
└── theme
...
├── config
└── locales
├── en.default.schema.json
├── es-ES.schema.json
...
Schema 结构
Schema locale 文件需要遵循特定的 命名结构。它们的基本结构如下:
- Category(类别):翻译的顶层分类。
- Group(分组):类别下的第二级分组。
- Description(描述):第三级,表示具体的翻译项。
{
"my_category": {
"my_group": {
"my_description": "translation text",
...
},
...
},
...
}
小贴士
命名翻译描述时尽量具有上下文意义。例如,blogs.article_comment.submit_button_text
比 blogs.article_comment.submit
更清晰地表达了上下文。
命名结构
Locale 文件的命名必须遵循标准的 IETF 语言标签规范,其中第一个小写字母代码代表语言,第二个大写字母代码代表地区。
例如:
语言 | 格式 |
---|---|
英语 - 英国 | en-GB.schema.json |
西班牙语 - 西班牙 | es-ES.schema.json |
法语 - 加拿大 | fr-CA.schema.json |
如果语言不区分地区,可以只使用 2 个小写字母的语言代码。
例如:
语言 | 格式 |
---|---|
芬兰语 - 所有地区 | fi.schema.json |
此外,你必须指定一个 默认 locale 文件。
默认 locale 文件
你必须指定一个默认的 locale 文件,格式为 *.default.schema.json
,其中 *
是你选择的语言代码。这个文件包含了主题默认语言的翻译。只能有一个默认文件。
大多数主题使用 en.default.schema.json
,将默认语言设为英文。
内容
Schema locale 文件支持为以下设置属性创建翻译:
父级 | 属性 |
---|---|
所有 settings | info 、label |
settings_schema.json 、Section schema |
block → name |
select |
group |
html 、number 、text 、textarea 、video_url |
placeholder |
range |
unit |
header 、paragraph |
content |
presets |
name 、category |
html 、inline_richtext 、liquid 、richtext 、text 、textarea 、url 、video 、video_url |
default |
用法
在使用 schema locale 文件时,你需要熟悉如何 引用 schema 翻译。
引用 schema 翻译
你可以通过以下格式的代码来访问 schema 翻译:
t:translation_category.translation_group.translation_name
例如,要让 product.liquid
section 的 name
属性可翻译,可以这样写:
{
"sections": {
"product": {
"name": "Product"
}
}
}
{% schema %}
{
"name": "t:sections.product.name",
...
}
{% endschema %}