i18next-shopify

The preset for the Shopify format of i18next. It reads nested plural keys and {name} placeholders, plus everything of react-i18next.

The i18next-shopify preset supports i18next-shopify, the i18next plugin for the Shopify message format.

Detection

The preset applies when the project depends on @shopify/i18next-shopify.

x18n.config.ts
import { i18nextShopify } from '@x18n/cli/presets'
import { defineConfig } from '@x18n/core'

export default defineConfig({
  presets: [i18nextShopify()],
})

What it adds

The preset includes everything of the react-i18next preset. If the react-i18next preset also applies, x18n adds the shared plugins one time.

The Shopify format keeps plural and ordinal forms as nested keys. The preset adds the derived keys {key}.plural, {key}.zero, {key}.one, {key}.two, {key}.few, {key}.many, {key}.other, and {key}.0 to {key}.9. New files use nested keys.

Locale files

The preset adds no resource patterns. Set resources in the config, or let x18n guess the locale directories:

x18n.config.ts
import { defineConfig } from '@x18n/core'

export default defineConfig({
  resources: [{ pattern: 'locales/{locale}.json' }],
})

Supported syntax

The calls of react-i18next. For this file, t('cart.items', { count }) uses cart.items.one and cart.items.other, so the unused-key check reports neither:

locales/en.json
{
  "cart": {
    "items": {
      "one": "{count} item",
      "other": "{count} items"
    }
  }
}

Placeholders

Braces: {name}. The placeholders of i18next stay: {{name}} and $t(key).

Extraction templates

The templates of react-i18next.