> For the complete documentation index, see [llms.txt](https://ascent.webvista.studio/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ascent.webvista.studio/webvista-studio-docs/kai-fa-zhe/jing-jian-metafields-shopify-fan-yi.md).

# 精简 metafields.shopify 翻译

Ascent 会在产品规格表、商品比较表等位置显示 Shopify 分类 metafields。字段名会通过类似下面的翻译键输出：

```liquid
{{ 'metafields.shopify.material' | t }}
```

Shopify 分类体系可能会在每个前台语言文件里生成非常大的 `metafields.shopify` 对象。如果店铺实际只使用少量分类 metafields，可以按需精简这些键，减少翻译文件体积。

## 哪些内容可以精简

只精简下面这个范围里的键：

```json
{
  "metafields": {
    "shopify": {}
  }
}
```

不要顺手删除其它翻译分组，除非已经确认它们没有被主题使用。

遇到以下情况时，需要保留对应的 `metafields.shopify` 键：

* 店铺产品实际使用了这个 Shopify 分类 metafield。
* 商品比较表区块里选择了这个 key。
* 不确定商家后续是否会继续使用这个字段。

如果删除了某个键，但主题仍然渲染 `{{ 'metafields.shopify.key' | t }}`，前台可能会显示缺失翻译提示。不确定时，优先保留。

## 准备保留清单

先创建一个文本文件，每行写一个需要保留的 key：

```txt
color
material
size
target-gender
```

这里只写 `metafields.shopify.` 后面的部分。例如 `metafields.shopify.material` 对应保留 `material`。

同时检查商品比较表区块里配置过的 key。Ascent 的商品比较表可以读取 `product.metafields.shopify[block.settings.key]`，这些手动配置的 key 也要放进保留清单。

## 批量精简前台语言文件

把保留清单保存为 `metafields-shopify-keep.txt`，然后在主题根目录运行：

```bash
node <<'NODE'
const fs = require("fs");
const path = require("path");

const keep = new Set(
  fs.readFileSync("metafields-shopify-keep.txt", "utf8")
    .split(/\r?\n/)
    .map((line) => line.trim())
    .filter(Boolean)
);

for (const file of fs.readdirSync("locales")) {
  if (!file.endsWith(".json") || file.endsWith(".schema.json")) continue;

  const filePath = path.join("locales", file);
  const json = JSON.parse(fs.readFileSync(filePath, "utf8"));
  const source = json.metafields?.shopify;

  if (!source || typeof source !== "object" || Array.isArray(source)) continue;

  const trimmed = {};
  for (const key of Object.keys(source)) {
    if (keep.has(key)) trimmed[key] = source[key];
  }

  json.metafields.shopify = trimmed;
  fs.writeFileSync(filePath, `${JSON.stringify(json, null, 2)}\n`);
  console.log(`${file}: kept ${Object.keys(trimmed).length} of ${Object.keys(source).length}`);
}
NODE
```

## 检查结果

精简后建议检查：

* 搜索主题里的 `metafields.shopify.`，确认需要的 key 都在保留清单中。
* 预览会显示产品规格表的商品。
* 预览使用了商品比较表的页面。
* 检查所有已启用的前台语言，尤其是默认语言。

Shopify 分类 metafield 的具体值来自产品 metafield 本身，例如 `value.label`。这里的 locale 翻译键只控制主题显示的字段名。
