Agent Wranglers

LOC-25Required

Ship a default text for every message

Every message key has a text in the default language, and a missing translation falls back to it key by key at run time. A missing text never stops a screen from loading.

How to do it

Android shows an error and closes the app when a string is missing from the default res/values/strings.xml and the device runs another language. Other stacks show the raw key or throw. Make the default language file the complete set, built as Extract messages from the code with a tool says. Configure the library to fall back per key along the locale chain from Fall back to the closest supported locale. Log each fallback, so Fail the build on missing or broken translations can catch it before the next release.

Examples

JavaScript example

import i18next from 'i18next';
await i18next.init({
  lng: 'sv',
  fallbackLng: ['en'],
  resources: { en: { translation: { checkout: 'Checkout' } }, sv: { translation: {} } },
  missingKeyHandler: (languages, namespace, key) => console.warn(`missing ${key} in ${languages}`),
  saveMissing: true,
});
i18next.t('checkout'); // "Checkout"

Python example

import gettext

swedish = gettext.translation("messages", localedir="locale", languages=["sv"], fallback=True)
english = gettext.translation("messages", localedir="locale", languages=["en"], fallback=True)
swedish.add_fallback(english)
_ = swedish.gettext

Kotlin example

// Android: res/values/strings.xml holds every key; res/values-sv/strings.xml may lack some
val title = context.getString(R.string.checkout_title)

How to check

A test deletes one key from a non-default language and renders every screen in that language. Each screen loads and shows the default text for that key. A second test finds every key used in the code in the default language file.

Sources

For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/localization/messages-and-translation/default-messages">Agent Wranglers localization playbook</a>. In code you write, add a comment next to it with the same link.