Workflow recipe
Translate app strings with AI and keep them consistent
A glossary per language, protected placeholders, plural and length checks in code, then human review.
Bookmark
Bookmarks are kept in your free account, so you can find this page again on any device.
Sign in to bookmarkOn this page
To translate app strings with AI and keep them consistent, give every source string a short note on where it appears, write a glossary and style notes for each language, and translate in batches with a prompt that forbids touching placeholders, tags and ICU syntax. Then run a check script that compares each translation with the source for placeholders, tags, plural forms, apostrophes and length, send everything it flags plus a sample of the rest to a native speaker, and look at the result in the running app.
Machine translation of whole sentences is now good; machine translation of app strings still breaks in small, predictable ways. A placeholder gets translated ({name} becomes {nom} and the user sees a raw brace). A plural message gets only the English one and other forms, so Polish users read “5 produkt”. “Save” is translated three different ways on three screens. A French elision puts an ASCII apostrophe in front of a placeholder, and the ICU parser quietly swallows the placeholder. None of these show up in a review of the JSON by eye. All of them are caught by a short script, which is the centre of this recipe.
EditorAbout 20 min
1. Give each source string its context
A translator, human or model, cannot translate “Save” or “Post” or “Order” well without knowing whether it is a button, a heading or a noun. Add a description for each key in a side file, and a maximum length where the layout is tight:
{
"cart.title": { "note": "Heading of the basket page", "max": 24 },
"cart.items": { "note": "Count of items under the basket heading; count is a number" },
"cart.checkout": { "note": "Primary button on the basket page", "max": 18 },
"order.shipped": { "note": "Email first line; name is the customer's first name" },
"invite.body": { "note": "Notification; inviter is a person's name, workspace is a team name" }
}Freeze the source strings for the batch. If English changes during translation, you will translate twice and the review queue will be wrong.
A shared documentAbout 25 min
2. Write a glossary and style notes per language
The glossary is how you keep translations consistent across batches and models. For each language, list:
- Product terms and their fixed translation, or “do not translate” for brand and feature names.
- UI verbs you use everywhere (“Save”, “Cancel”, “Delete”, “Share”) with the one translation to use.
- Register: formal or informal address (French vous or tu, German Sie or du, Spanish usted or tú), and whether buttons use the infinitive or the imperative.
- Typography: French uses a space before
:,;,?and!; German capitalises nouns; quotation marks differ by language.
Ask your reviewers to correct the glossary before the first batch, not after. If you already have translated strings, ask an assistant to propose the glossary from them, then have a reviewer check it.
Claude Code, Codex or a chat assistantAbout 30 min
3. Translate in batches with the syntax protected
Send 50 to 150 strings at a time with their notes and the glossary. Smaller batches keep the glossary in view; much larger ones drift. Tell the model which plural categories the target language needs. You can print them from your own runtime rather than trusting memory:
node -e 'for (const l of ["en","fr","pl","ar","ja","de"]) console.log(l, new Intl.PluralRules(l).resolvedOptions().pluralCategories.join(","))'en one,other
fr many,one,other
pl few,many,one,other
ar few,many,one,two,zero,other
ja other
de one,otherSave the JSON as the target file (for example locales/pl.json), and keep the “TOO LONG” and “NEW TERMS” lists for the review queue. In a coding agent, ask it to write the file and stop, not to run or change anything else.
EditorAbout 5 min
4. Add the check script to the repository
Save this as scripts/check-strings.mjs. It needs no dependencies and reads the plural categories from Node’s own Intl.PluralRules, which uses the Unicode CLDR data:
// Check translated ICU message files against the source file.
// Usage: node check-strings.mjs locales/en.json locales/pl.json pl
// Node 18 or later, no dependencies.
import { readFileSync } from "node:fs";
const [sourcePath, targetPath, locale] = process.argv.slice(2);
const source = JSON.parse(readFileSync(sourcePath, "utf8"));
const target = JSON.parse(readFileSync(targetPath, "utf8"));
const MAX_GROWTH = 1.4; // flag strings more than 40% longer than the source
// Placeholder names: {name}, {count, plural, ...}, {date, date, short}
const placeholders = (s) =>
[...s.matchAll(/\{\s*([A-Za-z0-9_]+)\s*[,}]/g)].map((m) => m[1]).sort().join(" ");
// HTML-like tags such as <b>...</b> or <link>...</link>
const tags = (s) => [...s.matchAll(/<\/?([a-z][a-z0-9]*)>/gi)].map((m) => m[0]).sort().join(" ");
// Plural categories used in the message: one {...}, few {...}, other {...}
const pluralCategories = (s) =>
[...s.matchAll(/\b(zero|one|two|few|many|other)\s*\{/g)].map((m) => m[1]);
const needed = new Intl.PluralRules(locale).resolvedOptions().pluralCategories;
const problems = [];
for (const [key, text] of Object.entries(source)) {
const t = target[key];
if (t === undefined || t.trim() === "") { problems.push(`${key}: missing`); continue; }
if (placeholders(t) !== placeholders(text))
problems.push(`${key}: placeholders differ (source "${placeholders(text)}", target "${placeholders(t)}")`);
if (tags(t) !== tags(text)) problems.push(`${key}: tags differ`);
if (/'[{}#|]/.test(t) && !/'[{}#|]/.test(text))
problems.push(`${key}: ASCII apostrophe before a syntax character quotes it; use ’ (U+2019) in text`);
if (/\bplural\b/.test(text)) {
const have = new Set(pluralCategories(t));
const missing = needed.filter((c) => !have.has(c));
if (missing.length) problems.push(`${key}: plural forms missing for ${locale}: ${missing.join(", ")}`);
}
// Plural and select messages grow with their extra branches, so skip the length check there
const branched = /\b(plural|select)\b/.test(text);
if (!branched && t.length > Math.max(text.length * MAX_GROWTH, text.length + 10))
problems.push(`${key}: ${Math.round((t.length / text.length) * 100)}% of source length, check it fits`);
}
for (const key of Object.keys(target)) if (!(key in source)) problems.push(`${key}: not in source`);
console.log(`${locale}: ${Object.keys(source).length} keys, ${problems.length} problems`);
for (const p of problems) console.log(` ${p}`);
process.exit(problems.length ? 1 : 0);The length rule allows short strings ten extra characters, because the W3C’s notes on text size cite IBM guidance that strings of up to ten English characters can grow by 200 to 300% in European languages. Tune MAX_GROWTH to your layout, and use each key’s max from step 1 if you want a hard limit.
TerminalAbout 15 min
5. Run the checks and fix what they find
node scripts/check-strings.mjs locales/en.json locales/pl.json pl
node scripts/check-strings.mjs locales/en.json locales/fr.json frOn test files we wrote with the usual mistakes planted in them, the script printed:
pl: 5 keys, 3 problems
cart.items: plural forms missing for pl: few, many
cart.checkout: 400% of source length, check it fits
order.shipped: placeholders differ (source "date name", target "date imie")
fr: 5 keys, 2 problems
cart.items: plural forms missing for fr: many
invite.body: ASCII apostrophe before a syntax character quotes it; use ’ (U+2019) in textFix placeholder, tag and apostrophe problems yourself or send those keys back to the model with the error; they are mechanical. Missing plural forms are a real bug for Polish, where “5 produktów” needs the many form. For French, CLDR’s many form applies to large round numbers such as a million; ICU falls back to other when it is missing, so decide per string whether it matters. Length problems go to the review queue with the screen they appear on.
When we ran the step 3 prompt for Polish in a fresh session, the model kept every placeholder, wrote all four plural forms and used the glossary’s “Do kasy” for the button. The script then flagged one string, invite.body, at 144% of the source length, because “workspace” became “obszaru roboczego”. That is the kind of finding the review queue is for.
Add the script to CI so no later change can merge a broken message file. It exits with 1 when it finds a problem.
A spreadsheet or your translation platformAbout 40 min
6. Send flagged strings to a native speaker
A fluent reviewer is the only check for meaning and tone. Make their time count by sending a queue, not the whole file. One row per string, with these columns: key, English, translation, note, screen or screenshot, reason for review, reviewer’s fix.
Put in the queue:
- every key the script flagged and you could not fix mechanically;
- everything on the “TOO LONG” and “NEW TERMS” lists from step 3;
- every string on screens that carry money, legal text, errors or consent;
- a random 10% of the rest, so you learn how good the unflagged translations are.
Ask the reviewer to fix the translation in place and to note any glossary change. Update the glossary before the next batch, so the same correction is not needed twice. If the random sample comes back with many fixes, review more of the batch before shipping it.
The running appAbout 15 min
7. Look at it in the app with real numbers
Some problems only appear on screen: truncated buttons, wrapped headings, sentences that read wrongly next to their neighbours, plurals that are grammatical but odd. Switch the app to each language and walk through the main screens. For every plural message, test the counts that hit each form, not only 1 and 2. For Polish that means 1, 2, 5, 22 and 25; for French include 0, 1, 2 and 1000000; for Arabic 0, 1, 2, 3, 11 and 100.
Format a few messages in code with your real message library too. With intl-messageformat 12.2.1, the French string Ouvrir l'{app} formats as Ouvrir l{app}, with a raw placeholder, because the ASCII apostrophe starts quoted text; with the typographic apostrophe it formats as “Ouvrir l’Notes”. The script in step 4 catches this, and seeing it once on screen explains why the rule is in the prompt.
Check it worked
Verification checklist
0 of 6 done
When it goes wrong
If the model returns a placeholder in the target language, such as {imie} for {name}, the prompt’s rule was not enough on its own; it happens most with placeholder names that are ordinary words. Fix them mechanically and keep the script in CI. Renaming placeholders in the source to something less word-like, such as {userName}, also helps.
If a placeholder silently disappears on screen in French or Italian, look for an ASCII apostrophe directly before a brace. ICU treats '{ as the start of quoted text, so l'{app} prints the literal l{app}. Use the typographic apostrophe ’ in translations, as the prompt says, or double the ASCII one.
If the same English word gets different translations across batches, the glossary did not include it, or the batch was too big for the model to keep the glossary in view. Add the term, re-run the affected keys, and keep batches under about 150 strings.
If the check flags every plural message as too long, your length rule counts the whole message. Four Polish branches are always longer than two English ones; our first version of the script made exactly this mistake. The version above skips the length check for plural and select messages, so check their branches on screen in step 7 instead.
If the JSON comes back wrapped in a code fence, with a list after it, or with missing keys, ask for “only a JSON object” again, and check the key count before saving. In an agent, have it validate the file with node -e 'JSON.parse(require("fs").readFileSync("locales/pl.json","utf8"))' before it stops.
Variations
For gettext .po files, the same rules apply with msgid and msgstr; tools in the gettext family check format strings, so run them in place of the placeholder check. For a translation management platform (Crowdin, Lokalise, Phrase and similar), use its glossary and checks, and use this recipe’s prompt for the machine translation step if the platform lets you choose the engine.
For marketing pages and help articles, translate whole documents rather than strings, and review all of it: tone matters more there and there is no layout to protect. To produce typed, schema-valid output from a model in code rather than in a chat, see structured outputs.
Related guides
Why AI hallucinates explains why a confident translation can still be wrong. The ICU message format guide and CLDR’s plural rules chart are the references behind the checks.
Outcome and tools
- Outcome
- Translated message files for one or more languages that pass automated checks for placeholders, tags, plural forms and length, with a native-speaker review queue and an updated glossary.
- For
- Developers, Product managers
- Variants for
- Claude Code, Codex
- Agent Skills
Related
- Extract structured data from PDFs
Turn a folder of PDF invoices into validated JSON with Docling, a Pydantic schema and structured outputs, plus a review file for every one that fails a check.
- Get reliable JSON from an LLM with structured outputs
Describe the output as a schema, let the provider enforce it, validate it with Pydantic AI or the AI SDK, and handle failures.
- Why AI hallucinates, and how to reduce it
AI hallucinations are fluent answers that are false. Why language models produce them, which ones you can prevent, and a checklist for work you depend on.
- Write code documentation from the source with an AI agent
A cited fact sheet first, docstrings with runnable examples, then proof that only docs changed and every example runs.