Schema 本地化文件
Schema locale 文件是以 .schema.json
为扩展名的 JSON 文件。它们用于托管各种设置模式属性的翻译字符串,以便将主题编辑器中的内容翻译为商店当前的语言。
要了解可以翻译哪些属性,请参考内容部分。
位置
Schema locale 文件位于主题的 locales
目录中:
└── theme
...
├── config
└── locales
├── es.schema.json
...
配置定义
Schema locale 文件需要遵循特定的命名结构。它们还遵循基本的组织结构:
- 类别:翻译的顶级类别。
- 组:在类别内部的第二级别组的翻译。
- 描述:第三级,代表单个的翻译。
{
"products": {
"product_list": {
"load_more_tip": "custom text",
...
},
...
},
...
}
提示
在命名翻译描述时,尽量提供足够的描述,以便为翻译提供上下文。例如:order.order_details.insuranceService_content_email
比 order.order_details.email
提供了更多的上下文信息。
文件命名
Locales 文件的命名必须遵循标准的 IETF 语言标记命名法,其中第一个小写字母代码代表语言,后面以 .schema.json
结尾。例如:
语言 | Schema | Storefront |
---|---|---|
English | en.schema.json | en.json |
Indonesian | id.schema.json | id.json |
Thai | th.schema.json | th.json |
警告
比较例外的是中文-简体、中文-繁体,它们分别是:
语言 | Schema | Storefront |
---|---|---|
中文-简体 | zh-hans-cn.schema.json | zh-hans-cn.json |
中文-繁体 | zh-hant-tw.schema.json | zh-hant-tw.json |
内容
Schema locale 文件允许你为以下设置属性创建翻译:
Parent | Attribute |
---|---|
All settings | info label |
settings_schema.json block Section schema | name |
select | group |
text textarea video_url handlebars | placeholder |
range | unit |
presets | name category |
使用
当使用 schema locale 文件时,你应该熟悉如何引用schema 翻译:
t:translation_top_level.translation_second_level.translation_third_level
以博客为例,我们有如下的 locales/en.schema.json
locale 文件:
{
"sections": {
"blog": {
"name": "Blog"
}
}
}
下面是 sections/blog.html
的 section 文件:
{{#schema}}
{
"name": "t:sections.blog.name",
...
}
{{/schema}}
下面是一个比较综合的例子:
{
"sections": {
"blog": {
"name": "Blog",
"presets": {
"presets__0": {
"category": "Content display",
"name": "Blog"
}
},
"settings": {
"title": {
"label": "Title"
},
"color_scheme": {
"label": "Color",
"info": "Adjust blog color scheme",
"options__0": {
"label": "None"
},
"options__1": {
"label": "Color 1"
}
}
}
}
}
}
{{#schema}}
{
"name": "t:sections.blog.name",
"settings": [
{
"type": "text",
"id": "title",
"label": "t:sections.blog.settings.title.label",
"default": "Blog"
},
{
"type": "select",
"id": "color_scheme",
"label": "t:sections.blog.settings.color_scheme.label",
"default": "none",
"options": [
{
"value": "none",
"label": "t:sections.blog.settings.color_scheme.options__0.label",
},
{
"value": "1",
"label": "t:sections.blog.settings.color_scheme.options__1.label",
}
]
}
],
"presets": [
{
"name": "t:sections.blog.presets.presets__0.name",
"category": "t:sections.blog.presets.presets__0.category"
}
]
}
{{/schema}}
这篇文章对你有帮助吗?