Skip to content

Key Concepts › Localization

Translation Files

Every piece of text your theme writes — buttons, headings, messages — comes from two files, one per language. Your templates never contain the words themselves.

The files

locales/
├── ar.json
└── en.json

Both are required. They are nested JSON, grouped however suits your theme:

{
  "nav": { "label": "Site", "other_language": "العربية" },
  "not_found": {
    "title": "Page not found",
    "home": "Back to the shop"
  }
}

Reading a string

Strings are data, under t, already in the page's language:

<h1>{{ t.not_found.title }}</h1>
<a href="/">{{ t.not_found.home }}</a>

There is no translation function to call and nothing to pass the language to.

The two files must match

A theme whose ar.json and en.json do not hold exactly the same keys is refused when it loads, and the error lists the keys that are missing and extra. This is checked rather than left to chance because the failure is silent: a key that exists in only one file renders as nothing in the other language — an empty button, a heading with no text — and nobody notices until a shopper does.

A key that exists in neither file also renders as nothing. There is no error at render time, so check your templates against your locale files: a typo like t.not_found.titel is an empty heading.

Writing good strings

  • Whole sentences. Arabic word order, agreement and plurals differ from English. A sentence assembled from fragments reads correctly in one language at most.
  • No markup. Strings are escaped when printed — <b> shows as text. Put the markup in the template and the words in the file.
  • Plurals. Arabic has six plural forms. Write out the phrases you need rather than building them from a count.
  • The language switch. Its label is written in the language it switches to: العربية in en.json, English in ar.json.