I18n strings and catalogs

From zakariaf/ReactNative-Skills · View interactive version

I18n strings and catalogs is an AI agent skill from the GitHub repository zakariaf/ReactNative-Skills. Puts all visible text in react-intl catalogs - semantic keys, CLDR plurals, Intl polyfills, parity. Use when adding UI text or a hard-coded string, a message key, a plural, a translation or a language (i18n). Not for RTL (rtl-and-direction).

How to use this skill

Skill file

UI text, catalogs and translations

Every word a person sees comes from a catalog key that exists in every language the app ships, each

language follows its own CLDR plural and script rules, numbers format the same in Jest and on the

phone, and zero-dependency checkers prove the catalogs and the code keep it that way.

Rules that must hold

  1. Render every visible or spoken string through t() or <T> from a catalog key. No literals in JSX (text runs, also after a {value}; string, template or ternary children), in text or accessibility props (accessibilityLabel, aria-label, alt, accessibilityValue.text, defaultValue, custom *Label/*Text/*Title/*Message props), in navigation options (options={{ title, tabBarBadge }}, navigation.setOptions), in Alert.alert titles, messages and buttons, in screen-reader announcements (announceForAccessibility, announce()), toasts (ToastAndroid.show), action sheets (ActionSheetIOS options and title), notification content (scheduleNotificationAsync) or Share.share. Why: a literal is one language on every phone, for screen readers too (VoiceOver, TalkBack), and {count} tasks left glues a sentence with Latin digits.
  2. Keep one flat catalog per language, src/i18n/catalogs/<tag>.json, for exactly the languages in src/i18n/languages.ts, each tag in BCP 47 canonical casing (en, pt-BR, zh-Hant) and the file named exactly so. The source language (SOURCE_LANGUAGE, usually en) is authoritative; every catalog has the same keys, sorted. No runtime fallback to the source: a missing key reaches onError. Why: stable diffs, a missing text fails a check, not a person, and pt-br.json loads on a Mac but not on Linux CI or EAS Build.
  3. Name keys <area>.<element>[.<variant>] (2-5 kebab segments) and write them as literals or in as const satisfies readonly MessageKey[] tables; never build or cast a key. Why: MessageKey = keyof typeof en and the checkers only see literal keys; a cast hides a typo; semantic keys survive rewording.
  4. Type every number: {n, number}, a skeleton ({rate, number, ::percent}) or a plural #. A plain {x} is only free text named *Name/*Text. Why: a plain argument prints String(value), Latin digits in every language.
  5. Write every counted noun as an ICU plural with exactly the CLDR categories of each language (new Intl.PluralRules(lang).resolvedOptions().pluralCategories: en one/other, ar zero/one/two/few/many/other, ja other), and the same =N branches in every language. Never branch on n === 1 in code. Why: Arabic needs six forms, Persian puts 0 in one, Russian puts 0 in many.
  6. One whole sentence per key, in the language's own script rules: no glued fragments, no literal digits, no bidi controls, Arabic-script punctuation (، ؛ ؟) in Arabic-script languages, ی/ک in Persian, Sorani and Urdu. Why: word order differs per language; look-alike characters break search, sorting and fonts.
  7. Let t() isolate free text (FSI…PDI) and never isolate twice: strip the inner isolates (stripIsolates) before a formatted text becomes a value of another message. Why: a Latin name inside an Arabic sentence must not reorder it, and nested isolates make CoreText run a date the wrong way.
  8. Force the FormatJS polyfills (Locale, PluralRules, NumberFormat) with data for exactly LANGUAGES, as the first import of the app entry index.ts (then expo-router/entry) and in every Jest setupFiles; a regional language imports the file each package ships, found by truncation fallback (the tag, then the tag minus its last subtag: pt-BR -> pluralrules pt.js), which is how the FormatJS polyfills and Node's ICU find plural data. Intl.DateTimeFormat (rule 10), RelativeTimeFormat, ListFormat, DisplayNames and Segmenter run only in src/i18n/, each on its own forced block; code never calls Intl.PluralRules. Why: Hermes has no PluralRules, Locale or those last four (not a constructor on the phone while Jest passes) and ignores -u-nu-; forcing makes Jest identical to the phone.
  9. Carry the numbering system in the locale tag (localeTagFor(language, digits): ar-u-nu-arab, ar-u-nu-latn) and use the same tag for messages and stand-alone numbers; never new Intl.NumberFormat('ar'). Why: CLDR defaults move (CLDR 48 switched ar to Latin digits) and the person may pick Latin digits.
  10. Format dates and times only at the edge, in src/i18n/, polyfilled, with an explicit calendar, an explicit time zone and the locale tag's digits. Intl.DateTimeFormat lives there on the forced @formatjs/intl-datetimeformat (data per language plus one time-zone file; it defaults to UTC, so pass timeZone). The template's day-month labels use CLDR month names copied into the catalogs instead, which needs no DateTimeFormat polyfill (about 1.2 MB raw for two languages); a time of day or other shapes take the Intl path (examples/intl-date-time.md); a relative time ("3 days ago") is a catalog plural. No {x, date}/{x, time} in catalogs, no toLocale*String or Intl.DateTimeFormat elsewhere. Why: native Hermes picks the device calendar and ignores the digit choice.
  11. Import react-intl only inside src/i18n/; send onError to the error log in the app and throw in tests. Why: one text API (useT, <T>), and a missing message fails the test run.
  12. Resolve the language as saved choice, then each device locale's full tag, language-Script, then language (explicit aliases first), then the source; declare supportedLocales = LANGUAGES (readAppLanguages) in the expo-localization plugin. Autonyms are code, never catalog text. Why: iOS Settings and Android 13+ per-app language list only declared languages; guessed mappings pick the wrong script.
  13. Keep permission purpose strings and the app name in the catalogs (<area>.<topic>.usage-description, app.name) as plain text. app.config builds locales from them (nativeLocales, keeping the variant's label), lists every purpose key it sets in NATIVE_TEXT_KEYS, gives a plugin its base text with sourceText, and holds no literal purpose string. Why: iOS prints them from InfoPlist.strings, where nothing formats ICU; a literal is one language for everyone and a second copy drifts.
  14. Translate source first, then every language with the same placeholders; drafted translations go on the non-blocking review queue (review-sheet.ts); approved copy is synced (sync-copy.mjs), never retyped; developer-only keys stay untranslated only through untranslatedPrefixes. Why: drafts need a fluent reader without stopping work, and retyping loses ’ – and ZWNJ.

Workflow

  1. First time (the app has no i18n layer). Read references/runtime-and-provider.md. Install the packages its table names (react-intl and the four @formatjs/intl-* polyfills exact, intl-datetimeformat only for rule 10's Intl path; npx expo install expo-localization; dev: @formatjs/cli, @formatjs/icu-messageformat-parser). Copy templates/src/i18n/ (catalogs, polyfills, languages, digits, bidi, t(), <T>, provider, dates, language resolution, translate-now.ts for text outside the provider, each with its test), templates/src/core/dates/date-key.ts if the app lacks it, templates/index.ts, templates/test/i18n/, templates/scripts/i18n/ and templates/contracts/i18n.json. In package.json set "main": "index.ts" and the script "i18n:verify": "node scripts/i18n/verify-catalogs.ts" (quality-gates' npm run verify, which CI runs, calls it). Set LANGUAGES, SOURCE_LANGUAGE, autonyms and directions in languages.ts, the digits rows in digits.ts, one locale-data import per language in intl-polyfills.ts and one catalog per language. An app that keeps the i18n folder elsewhere sets I18N_DIR in scripts/i18n/app-languages.ts and "i18nDir" in rn-skills.config.json together. Render <I18nProvider language digits onError> in the root layout src/app/_layout.tsx (language from resolveLanguage(saved, getLocales())), with design-system-structure's <TextLocaleProvider value={{ language, direction: directionOf(language) }}> inside it, and title screens in a group layout under it, src/app/(app)/_layout.tsx (useT() throws outside the provider). Text shown outside the provider (the root crash fallback) uses createTranslateNow(onError) from translate-now.ts: no React context, the language and digits the provider showed last (the template catalogs carry its crash.title, crash.body and crash.restart keys). Wrap app.config.ts's result in withI18n (runtime reference, "Declaring the languages"): locales from the catalogs with the variant's name, expo-localization's supportedLocales from readAppLanguages(projectRoot).
  2. Adding a language. Add it to LANGUAGES, write <lang>.json with every key (source first), add its two locale-data imports and its digits.ts row, messages.ts entry, autonym and direction (supportedLocales follows LANGUAGES through readAppLanguages). check-catalogs.mjs then tells you every plural that lacks one of its CLDR categories. A regional or script language (pt-BR, zh-Hant) imports the locale-data file each package ships (check-i18n-code.mjs names it) and may need an alias for how phones report it (Android: zh-TW).
  3. Building or changing a screen. Look for existing keys first. Use keys as literals: <T id="tasks.summary.open" values={{ openCount }} />, or t('…') in the model hook for props, accessibility labels and navigation options. Components receive translated strings; they never build them. An id that arrives at runtime (a game's message id, a server code mapped to a key) goes through translateRuntimeMessage(t, { id, values }, onError) from templates/src/i18n/runtime-message.ts, which checks it against the source catalog instead of casting it.
  4. Text the catalogs lack. Read references/catalogs-keys-and-icu.md and references/translation-workflow.md, and follow examples/add-a-counted-message.md: source text first, then every language with the same placeholders and each language's plural categories, keys sorted, drafts on the review queue.
  5. Approved copy (when design or marketing owns the texts). Keep it in contracts/copy-source.json (shape: examples/copy-source.json); look up with node ${CLAUDE_SKILL_DIR}/scripts/sync-copy.mjs keys . --screen <id> --lang all, write with apply . --screen <id>; a wording change goes into the copy source first.
  6. Permission texts and the app name. Add <area>.<topic>.usage-description keys (plain text) to every catalog and list each in withI18n's NATIVE_TEXT_KEYS (NSCameraUsageDescription: 'permissions.camera.usage-description'); nativeLocales builds app.config locales from the catalogs. A config plugin that writes the base text gets it from the catalogs too: ['expo-image-picker', { cameraPermission: sourceText(projectRoot, 'permissions.camera.usage-description'), photosPermission: false, microphonePermission: false }] (false for each permission it never asks: an installed plugin writes an English default otherwise). When the permission flow itself is the task, hand off to permissions-and-system-prompts.
  7. Tests. Keep the template tests green. A message with a count or a placeholder gets a t() assertion in each language whose grammar differs (Arabic: 0, 1, 2, 3, 11, 100). Component tests render through unit-and-component-tests' renderWithProviders, whose test/test-app.tsx mounts I18nProvider (real catalogs, a throwing onError), not a bare IntlProvider: <T> and useT() need its TContext (runtime reference, "Jest setup").
  8. Run the checks from the repo root, fix every FAIL line (each names the file, the rule and the fix) and rerun until each prints RESULT: PASS:

Look up a rule id or a bad-input exit in references/checkers-and-contracts.md (every option, contract key and SKIP line). When multi-package, add --app-dir <workspace> (for example apps/mobile) to each. Then npx jest src/i18n scripts/i18n test/i18n --ci and npm run i18n:verify (the in-repo gate CI runs without the skill: FormatJS verify plus the same catalog linter).

  1. The review queue (never blocking). Run node scripts/i18n/review-sheet.ts: it writes reports/i18n/review-<lang>.csv for each reviewLanguages entry and prints REVIEW PENDING (not blocking): …. Copy that line into the report with the questions from the translation-workflow reference and carry on. When corrections arrive, apply them (copy source first), rerun the checks, then node scripts/i18n/review-sheet.ts --mark-reviewed <lang> --date YYYY-MM-DD.

Definition of done

Anti-patterns

Files in this skill

| File | What it is | Read/run when |

|---|---|---|

| references/catalogs-keys-and-icu.md | Catalog files, key grammar, placeholders, plurals per CLDR, bidi isolation, system texts, untranslated keys, dates, script rules, every catalog rule, what FormatJS verify misses | Workflow steps 2-4, and when a catalog check fails |

| references/runtime-and-provider.md | Packages and versions, why the polyfills are forced (the DateTimeFormat block, the Intl APIs Hermes lacks), regional and script languages (locale-data fallback, device matching), a moved i18n folder, the custom entry, the i18n folder and i18n:verify, language resolution and expo-localization on iOS and Android, withI18n (variant label, plugin base texts), locale tags, t()/<T>/provider and where titled screens go, Jest, device probes, multi-package | Workflow steps 1 and 6, and when changing runtime i18n code |

| references/translation-workflow.md | Writing a new message, the copy source and sync-copy.mjs, glossary and tone, the review queue, reviewer questions, store listings | Workflow steps 4, 5 and 9 |

| references/checkers-and-contracts.md | Every checker option, contracts/i18n.json and contracts/copy-source.json keys, rn-skills.config.json keys, SKIP lines, multi-package setup | Workflow step 8: a FAIL rule, a bad-input exit, or an app layout that differs |

| examples/add-a-counted-message.md | A new plural message in en, de, fa and ar, from key to test to checks | Workflow step 4 |

| examples/copy-source.json | The shape of contracts/copy-source.json | Workflow step 5 |

| examples/intl-date-time.md | Times of day with Intl.DateTimeFormat in src/i18n/: the polyfill block, explicit calendar and time zone, verified outputs and test | When a date or time needs more than catalog month names (rule 10) |

| templates/src/i18n/ | The runtime: catalogs (en, ar); intl-polyfills.ts, intl-status.ts (+ test), languages.ts, digits.ts, bidi.ts, language-context.tsx, translate-now.ts (+ test: t() without React context, for the crash fallback) (synced from the library: change them there); messages.ts, create-t.ts, t-context.ts, t-bridge.tsx, i18n-provider.tsx, t.tsx, format-date.ts, resolve-language.ts, with tests; runtime-message.ts (+ test: isMessageKey, translateRuntimeMessage for ids that arrive at runtime) | Workflow steps 1 and 3; copy to src/i18n/ |

| templates/src/core/dates/date-key.ts | Civil-date keys format-date.ts reads (synced from seeded-determinism-and-golden-vectors) | Workflow step 1, only if the app lacks it |

| templates/index.ts | The custom app entry: polyfills first, expo-router/entry last | Workflow step 1 |

| templates/test/i18n/ | Guardrail test that the entry imports the polyfills first | Workflow step 1 |

| templates/scripts/i18n/ | verify-catalogs.ts (npm run i18n:verify: FormatJS verify + the linter catalog-lint*.ts, icu-walk.ts, which prints the checker's rule ids, lines and messages for L1-L13, P4, P5 and F1; FormatJS reports missing and extra keys and placeholder types itself), native-locales.ts (app.config locales, sourceText), app-languages.ts (LANGUAGES for Node tooling, read without importing app code), i18n-contract.ts (finds contracts/ at the repo root), review-sheet.ts (the review queue), with tests | Workflow steps 1, 6 and 9 |

| templates/contracts/i18n.json | The app's i18n contract: untranslated prefixes, review languages, isolated formatters, package catalogs | Workflow step 1 |

| scripts/check-catalogs.mjs | Checks every catalog: L1-L13, parity P1-P5, files F1 (BCP 47 casing, exact file names), plural categories and scripts from Node's ICU | Workflow step 8, after every catalog change |

| scripts/check-i18n-code.mjs | Checks source for literal text (JSX, props, navigation, alerts, announcements, toasts, action sheets, notifications, share sheets), plural forms picked in code, built, cast or unknown keys (also the keys app.config names), react-intl, date, number and Hermes-missing Intl APIs, nested isolates, runtime files, polyfill data (per installed file) and order, Jest setup, the i18n:verify script, the tooling's i18n folder, declared languages and permission texts in app.config | Workflow steps 1 and 8 |

| scripts/sync-copy.mjs | Looks up (keys), writes (apply) and verifies (check) approved copy against the catalogs | Workflow steps 5 and 8 |

| scripts/lib/catalog-rules.mjs | The catalog rule implementations and messages | Read only when changing a rule |

| scripts/lib/i18n-config.mjs | Reads languages.ts, the contract and the catalog folders for every checker | Read only when changing a checker |

| scripts/lib/icu-parse.mjs | Dependency-free ICU MessageFormat parser (FormatJS element shapes) | Read only when changing a checker |

| scripts/lib/jsx-text.mjs | Finds the text a JSX element renders (runs, literal, built and ternary children) | Read only when changing a checker |

| scripts/lib/app-config-rules.mjs | Literal purpose strings, uncovered purpose keys, plugin option to Info.plist key table, supportedLocales | Read only when changing a checker |

| scripts/lib/source-scan.mjs | JSX, call and import scanning (synced from the library) | Never by hand |

| scripts/lib/ts-literal.mjs | Reads LANGUAGES as a literal (synced from the library) | Never by hand |

| scripts/check-lib.mjs | Shared script helper (synced from the library) | Never by hand |

| scripts/selftest.mjs | Proves every checker passes its good fixtures and catches each planted bug | After changing a script or fixture |

| assets/i18n-contract.schema.json | JSON Schema of contracts/i18n.json | When editing the contract |

| assets/copy-source.schema.json | JSON Schema of contracts/copy-source.json | When creating a copy source |

| assets/shared.json | The shared files this skill copies in | When adding a shared file |

| tests/bases/ | Base trees the fixtures build on (four-language catalogs, a small app, package catalogs, a copy source) | When adding a fixture |

| tests/fixtures/ | Good, planted-bad, pass and error cases, one folder per checker suite | When adding a rule |

Related skills

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.