Mrs. Sri adds a new line to the booking card: "Breakfast included". Now the Indonesian, Japanese and Arabic dictionaries each need that sentence, and the sentence for an old button that was renamed has to come out. Checked by hand, something always slips. Once an app has four languages, its translation files need rules: where files live, which format they use, how keys are named, and who checks which file fell behind. That last part is the job of an extract tool: it reads the code, lists the keys it uses, and compares them with every file.
File layout: per locale, per namespace
locales/
en-US/booking.json ← the source, written by Mrs. Sri
en-US/admin.json ← Mrs. Sri's dashboard
id-ID/booking.json
ja-JP/booking.json
ar-EG/booking.json
- One folder per locale, one file per namespace (feature). Our booking card dictionaries are small: the JSON file (2-space indent) is 392 bytes for id-ID up to 1,039 bytes for ar-EG, which needs 20 keys because Arabic has six plural categories. Once built, Vite turns each file into a JavaScript module, so the chunks are bigger: 518 to 1,316 bytes (the i18n at Production Scale lesson).
- Namespaces can be lazy-loaded: guest pages load only
booking.json;admin.jsonis fetched when the dashboard opens. With i18next,useTranslation('admin')triggers the load throughi18next-http-backend(loadPath: '/locales/{{lng}}/{{ns}}.json') ori18next-resources-to-backend1.2.3 (resourcesToBackend((lng, ns) => import(`./locales/${lng}/${ns}.json`)), so each file becomes its own chunk in the bundle). - Files per feature also mean fewer conflicts: the admin team and the booking team don't edit the same file.
- A small app may keep one file per locale (
messages/ja-JP.json, next-intl style) with namespaces as the outermost keys.
Formats: JSON, ICU, XLIFF, PO
The same text, the book button, in four formats:
// i18next JSON v4 (locales/ja-JP/booking.json)
{ "book": "予約する(お支払いは現地で)" }
// ICU JSON (react-intl, next-intl, i18next-icu)
{ "booking.book": "予約する(お支払いは現地で)" }
<!-- XLIFF 2.0 -->
<xliff xmlns="urn:oasis:names:tc:xliff:document:2.0" version="2.0" srcLang="en-US" trgLang="ja-JP">
<file id="booking">
<unit id="book">
<notes><note category="description">Main button of the booking card. The guest pays cash on arrival. Max. 32 characters.</note></notes>
<segment><source>Book now, pay at the homestay</source><target>予約する(お支払いは現地で)</target></segment>
</unit>
</file>
</xliff>
# PO (gettext)
#. Main button of the booking card. The guest pays cash on arrival. Max. 32 characters.
msgctxt "booking"
msgid "Book now, pay at the homestay"
msgstr "予約する(お支払いは現地で)"
| Format | Used by | When to pick it |
|---|---|---|
| i18next JSON v4 | i18next, react-i18next | Apps that read the file directly; plurals through _one/_other suffixes |
| ICU JSON | react-intl, next-intl, FormatJS | Sentences with plural and select inside one message |
| XLIFF | Professional translation tools (CAT tools, TMS), Angular | Exchanging files with translators: source, translation, notes and status in one file |
| PO (gettext) | PHP, WordPress, Python/Django, Poedit | Projects already on gettext; plurals use their own Plural-Forms formula |
Key names: semantic or source text
- A semantic key (
book,booking.total) names the text's role. The text can change without touching the code or the other translations. - Source text as the key (gettext style:
t('Book now, pay at the homestay'), in i18next withkeySeparator: falseandnsSeparator: false) reads nicely in code. But fixing one typo changes the key, and every translation of the old key is lost. One word also can't carry two meanings: English "Book" can mean a book to read or to reserve. - Good names: feature plus role (
booking.book,inbox.title), notbtn1ortext2. An old key that was renamed must be removed from every file; otherwise it becomes an unused key.
Finding missing and unused keys
The booking card code uses 10 keys: room, perNight, checkIn, group, nights and total (with count), book, cancel, breakfast, thanks. A plural key needs one form per Intl.PluralRules category of that language:
const used = ['room', 'perNight', 'checkIn', 'group', 'nights', 'total', 'book', 'cancel', 'breakfast', 'thanks'];
const plural = new Set(['nights', 'total']);
const ORDER = ['zero', 'one', 'two', 'few', 'many', 'other'];
function expected(locale) {
const cats = new Intl.PluralRules(locale).resolvedOptions().pluralCategories.sort((a, b) => ORDER.indexOf(a) - ORDER.indexOf(b));
return used.flatMap((k) => (plural.has(k) ? cats.map((c) => `${k}_${c}`) : [k]));
}
function check(locale, file) {
const want = expected(locale);
return { missing: want.filter((k) => !(k in file)), unused: Object.keys(file).filter((k) => !want.includes(k)) };
}
check('ja-JP', jaJP); // { missing: ["book", "cancel", "breakfast"], unused: ["payAtHomestay"] }
check('ar-EG', arEG); // { missing: ["nights_zero", "nights_few", "nights_many", "total_zero", "total_one", "total_two", "total_few", "total_many", "breakfast", "thanks"], unused: [] }
ja-JP still has payAtHomestay, the old name of book before Mrs. Sri renamed it; that's why book is missing and payAtHomestay is unused. ar-EG is missing 10 keys, eight of them plural forms English doesn't need.
Automatic extraction: i18next-cli and formatjs
i18next-parser is deprecated; npm says "use i18next-cli instead". i18next-cli 1.75.2 reads the code and the files together:
// i18next.config.js
export default {
locales: ['en-US', 'id-ID', 'ja-JP', 'ar-EG'], // the first one = primary language
extract: { input: 'src/**/*.{ts,tsx}', output: 'locales/{{language}}/{{namespace}}.json' },
};
$ npx i18next-cli status ja-JP
Key Status for "ja-JP":
Overall: [■■■■■■■■■■■■■■□□□□□□] 70% (7/10)
3 absent
✓ room
...
✗ book (absent)
✗ cancel (absent)
✗ breakfast (absent)
✓ thanks
npx i18next-cli statussums up each language;status ja-JPlists every key;status --unusedlists unused keys without changing any file.npx i18next-cli extractrewrites the files: missing keys get""in the other languages, unused keys are deleted (removeUnusedKeys: trueby default).
What extract did to our project, measured: the en-US source keeps nights_one and nights_other, and every missing key in the other languages gets "", plural forms included. But payAtHomestay in ja-JP counts as unused and is deleted: the Japanese text of the button, "予約する(お支払いは現地で)", is gone, and book comes back as "". A source language with only the other category, such as Indonesian or Japanese, has it worse. i18next-cli 1.75.2 then uses its plural keys without a suffix: it deletes nights_other and adds "nights": "nights". It also fills the missing plural forms of ar-EG with "nights", which status counts as translated. To prevent it: rename a key in every file before you run extract (move the Japanese text from payAtHomestay to book), run extract on a branch, and read the git diff before you commit.
For react-intl, formatjs (@formatjs/cli 6.16.34) collects messages from FormattedMessage and defineMessages: npx formatjs extract 'src/**/*.tsx' --out-file lang/en-US.json writes { "booking.book": { "defaultMessage": "Book now, pay at the homestay", "description": "..." } }.
Context for translators
Translators see only the text, not the page. Without context, "Book" may be translated as "本" (a book to read). Give every key: a description (the description field in FormatJS, <note> in XLIFF, a #. comment in PO), a length limit ("max. 32 characters"), what each slot means ({{count}} is the number of nights, {{name}} the guest's name), and a screenshot of that part of the page. Translation platforms (TMS) can show all of that next to the text.
⚠️ When can extract and status fool you?
extractwithout reading the diff. A renamed key such aspayAtHomestayinja-JPis deleted as unused, and its translation goes with it.- Empty strings from
extract. In i18next 26 and older,""counts as a translation (returnEmptyString: trueby default), so theja-JPbutton shows empty. SetreturnEmptyString: falseso""falls to the fallback language. Since i18next 27 that is the default. Another option isextract.omitMissingKeys(i18next-cli 1.86), so untranslated keys are not written at all. - 100% status isn't proof. With a source language that has only
other, the"nights"filler inar-EGcounts as translated. Also look for values equal to their key's name. - Dynamic keys.
t(`status.${code}`)can't be read by extract, so it gets deleted as unused. Write keys in full, or list the pattern inpreservePatterns.
TL;DR: Keep dictionaries per locale and per namespace (locales/ja-JP/booking.json), so each feature can be lazy-loaded (only the translations needed are loaded) and managed on its own. JSON v4 for i18next, ICU JSON for react-intl and next-intl, XLIFF for exchanging with translators and CAT tools, PO for gettext projects. Use semantic keys (booking.book), not source text. A missing key = used by the code (with every plural category of that language) but absent from the file; an unused key = in the file but not used by the code: ja-JP lacks book, cancel, breakfast and still holds payAtHomestay. i18next-parser is deprecated; use npx i18next-cli status and extract (i18next-cli 1.75.2), or formatjs extract for react-intl. Always read the diff: extract deleted payAtHomestay from ja-JP, and its Japanese text with it. Set returnEmptyString: false (the default since i18next 27), and give translators descriptions, length limits, slot meanings and screenshots.
⚡ One folder per locale, one file per feature
Write:
locales/
en-US/booking.json ← the source, written by Mrs. Sri
en-US/admin.json ← Mrs. Sri's dashboard
id-ID/booking.json
Meaning: Each file is one namespace. Namespaces can be lazy-loaded: guest pages load only booking.json, and admin.json is fetched when the dashboard opens. Files per feature also mean fewer conflicts, because the admin team and the booking team don't edit the same file.
⚡ Missing keys and unused keys
Write:
check('ja-JP', jaJP); // { missing: ["book", "cancel", "breakfast"], unused: ["payAtHomestay"] }
Guess first: why is book missing, when the button is already translated into Japanese?
Its translation still sits under payAtHomestay, the old name of book before Mrs. Sri renamed it. So book is missing and payAtHomestay is unused.
Meaning: A missing key is used by the code (with every plural category of that language) but absent from the file. An unused key is in the file but not used by the code.
⚡ Read the diff after extract
Meaning: npx i18next-cli extract rewrites the files. In our project it deleted payAtHomestay from ja-JP as unused, and the Japanese text of the button went with it. Run extract on a branch, then read the git diff before you commit.