Sub topic 15
Keeping Translations Complete as the App Grows
Assume you know basic Dart, null safety, Flutter widgets, MaterialApp, YAML, and JSON. This chapter focuses on the translation workflow after gen-l10n is already configured.
Treat the template ARB as the source of truth
The template ARB file, such as lib/l10n/app_en.arb, defines the message catalog. Each message key becomes part of the generated AppLocalizations API.
When you add a user-visible string:
- Add a stable key to the template ARB file.
- Add its description and placeholder metadata.
- Add the same key to every supported translated ARB file.
- Run
flutter gen-l10n. - Test the message in each important locale.
Do not edit the generated Dart file. The next generation step replaces it.
{
"profileTitle": "Profile",
"@profileTitle": {
"description": "Heading for the user's profile screen"
},
"welcomeBack": "Welcome back, {name}!",
"@welcomeBack": {
"description": "Greeting shown when a signed-in user opens the app",
"placeholders": {
"name": {
"type": "String",
"example": "Ada"
}
}
}
}A translated file repeats the message keys and supplies translated values:
{
"@@locale": "es",
"profileTitle": "Perfil",
"welcomeBack": "¡Te damos la bienvenida, {name}!"
}The key must match exactly. The placeholder name must also match exactly. A translator may change the position of {name}, but must not rename or remove it.
Make missing messages visible
Configure l10n.yaml to write a report for messages that are missing from translated files:
arb-dir: lib/l10n
template-arb-file: app_en.arb
output-localization-file: app_localizations.dart
synthetic-package: false
untranslated-messages-file: build/untranslated_messages.txtRun the generator after changing an ARB file:
flutter gen-l10n
cat build/untranslated_messages.txtUse this report during development and continuous integration (CI), which is an automated build check. A nonempty report should fail the check unless the missing translation is intentionally tracked.
| Change | Required action | Common failure |
|---|---|---|
| New message key | Add it to every locale | One language silently falls back |
| New placeholder | Update every translation | Generation or runtime formatting error |
| Removed message | Remove it from every locale | Stale translation remains |
| Changed meaning | Update description and translations | Old wording survives review |
Review translations as a workflow
Keep the template file easy to review. Use descriptions that explain where a message appears and what its placeholders mean. Avoid embedding business data in translated text.
When a message changes, translators need the new context. Update the description metadata when the meaning or screen changes. For plural or select messages, verify every branch. Test long translations because some languages need more space than English.
Common errors include using the English sentence as a key, changing a key after translations exist, and adding a placeholder in only one locale. Prefer stable keys such as welcomeBack over keys such as welcomeBackAda. The value can change without forcing a code change.
Exercise
Exercise
You add tripCount to app_en.arb, but the Spanish ARB file does not contain it. What should you check before releasing?
Show answer
Run flutter gen-l10n, inspect the untranslated-messages report, add the Spanish translation with the same key and placeholder names, then test the message with the Spanish locale.