LOC-19Recommended
Fail the build on missing or broken translations
Before release, every key in the source exists in each published language, and every translation has the same placeholders as its source.
How to do it
A missing key shows the raw key or the source language mid-page. A translation that drops {name}, or spells it {nom}, breaks the sentence or throws at run time. Compare each language file with the source after every extraction. Check placeholders and ICU plural branches per key, and parse every message. Tools such as msgfmt --check do this for gettext files. A language below 100% stays unpublished, or falls back to the default language key by key, and the build says which. Choose plural forms as Get plurals right in every language says.
Examples
JavaScript example
const placeholders = message => new Set([...message.matchAll(/\{(\w+)/g)].map(match => match[1]));
for (const [key, source] of Object.entries(sourceMessages)) {
const translated = svMessages[key];
if (!translated) throw new Error(`sv is missing ${key}`);
const same = [...placeholders(source)].sort().join() === [...placeholders(translated)].sort().join();
if (!same) throw new Error(`sv ${key} has other placeholders than the source`);
}
Python example
import re
def placeholders(message: str) -> set[str]:
return set(re.findall(r"\{(\w+)", message))
for key, source in source_messages.items():
translated = sv_messages.get(key)
assert translated, f"sv is missing {key}"
assert placeholders(source) == placeholders(translated), f"sv {key} has other placeholders than the source"
How to check
A test loads each published language. Every source key is present, every message parses, and the set of placeholders in each translation equals the set in its source.
Sources
Related rules
- LOC-25 Ship a default text for every message in Localization
- LOC-12 Get plurals right in every language in Localization
- LOC-20 Mark translations stale when the source changes in Localization
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/translation-completeness">Agent Wranglers localization playbook</a>. In code you write, add a comment next to it with the same link.