> For the complete documentation index, see [llms.txt](https://webvista-studio.gitbook.io/krank/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://webvista-studio.gitbook.io/krank/others/translation-file-cleanup.md).

# Translation File Cleanup

Krank displays Shopify category metafields in areas such as Product Specifications and Product Compare Table. Field names are output through translation keys similar to:

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

Shopify category taxonomy can generate a very large `metafields.shopify` object in each storefront language file. If a store only uses a small set of category metafields, these keys can be trimmed as needed to reduce translation file size.

## What To Trim

Only trim keys inside this range:

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

Do not remove other translation groups unless they have been confirmed unused by the theme.

Keep a `metafields.shopify` key when:

* Store products actually use this Shopify category metafield.
* A Product Compare Table block is configured with this key.
* The merchant may continue using this field later.
* The field label needs exact wording, punctuation, acronyms, or special capitalization.

If a key is removed while the theme still renders `{{ 'metafields.shopify.key' | t }}`, the storefront may show a missing translation string or a machine-style key. When unsure, keep the key.

## Where Krank Uses These Keys

Krank builds category metafield labels dynamically in:

```
blocks/_product-attributes.liquid
blocks/_compare-table-category.liquid
```

The Product Specifications block loops through `product.metafields.shopify`. The Product Compare Table category block reads keys from block settings and then uses `product.metafields.shopify[key]`.

Also check product templates and listing presets:

```
templates/product*.json
listings/*/templates/product*.json
```

For example, a compare table may use configured keys such as `shopify.vehicle-oil-features` or `shopify.viscosity`.

## Prepare A Keep List

Create a text file with one key per line:

```txt
color
material
size
target-gender
vehicle-oil-features
viscosity
```

Only write the part after `metafields.shopify.`. For example, `metafields.shopify.material` becomes `material`.

Include:

* Keys used by real products.
* Keys configured in Product Compare Table blocks.
* Keys used by presets or demo products.
* Keys that should keep exact human-written labels.

## Batch Trim Storefront Locale Files

Save the keep list as `metafields-shopify-keep.txt`, then run this from the theme root:

```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
```

This trims only storefront translation files. It skips schema translation files such as `en.default.schema.json`.

## Optional Fallback

If the theme should tolerate missing category metafield translations, add a Liquid fallback before trimming aggressively:

```liquid
{% liquid
  assign translation_key = 'metafields.shopify.' | append: key
  assign translated_label = translation_key | t
  assign fallback_label = key | replace: '-', ' ' | capitalize
%}

{% if translated_label == translation_key %}
  {{ fallback_label }}
{% else %}
  {{ translated_label }}
{% endif %}
```

This keeps labels readable when a low-priority key is removed, but exact translations are still better for labels with acronyms, symbols, slash-separated wording, or unusual capitalization.

## Check The Result

After trimming:

* Search for `metafields.shopify.` and confirm required keys are in the keep list.
* Preview a product that displays Product Specifications.
* Preview a page that uses Product Compare Table.
* Check all enabled storefront languages, especially the default language.
* Confirm the storefront does not show raw strings such as `metafields.shopify.` or unresolved hyphenated keys.

The category metafield values come from the product metafield itself, such as `value.label`. These locale keys only control the displayed field names.
