# Translate your app with an LLM without breaking the placeholders

- Author: RomanMotion (https://wurk.fun/user/RomanMotion)
- Published: 2026-11-09
- Canonical (HTML): https://wurk.fun/blog/translate-your-app-with-an-llm-without-breaking-the-placeholders
- Cover image: https://ik.imagekit.io/wurk/browser-uploads/f1c626b5c17e7f0a61dfbbe7a20d85ae7b33a20527243aeec2ee1d0a8b87562a/22893bea-c260-4d38-95af-b97173f020ce/cover-i18n.jpg?wurkUpload=v1.7TDrDaWID1qZdDYp5_MxPKGE-YkIF_Tl4XAI2MyRUjo

---

You've asked an LLM to translate your app's strings, and the new language file looks ready to ship. Then a customer sees `{name}` on screen, a plural reads strangely, or a button cuts off its label. This workflow gives you a prompt, a script, and a UI check to catch those problems before release.

Translate a small batch at a time, keeping keys and runtime variables intact. Validate each batch against its source, handle ICU messages with an ICU-aware parser, and check the result in the actual interface. Finally, ask a native speaker to review the screens people use most.

## Start with the parts that can break

A translation file contains text for people and syntax for your app. The words can change; the JSON keys and variable names must still match what your code expects.

For example, if the source says `"welcome": "Hello, {name}"`, the translation needs the key `welcome` and the placeholder `{name}`. The surrounding words can move to fit the target language. ICU's documentation explicitly allows the variable parts to be rearranged for grammar ([ICU message formatting](https://unicode-org.github.io/icu/userguide/format_parse/messages)).

HTML needs attention too. A translated message may contain a link or emphasis tag. If a tag is dropped, malformed, or wrapped around the wrong words, the screen may look or behave differently. Check the markup in context rather than assuming that valid-looking JSON means the message is correct.

Then there's space. A label that fits a button in English may need more room in another language. A file check can tell you whether a value is empty; it cannot tell you whether the text is clipped on a phone.

Keep the source file unchanged and work on a separate target file. That gives you a clear comparison and a way back if a batch goes wrong.

## Translate in small batches with a glossary

Use a flat JSON object for the workflow below: each key maps directly to a string. If your files are nested, adapt the check to your structure or export a flat batch first. Don't paste credentials, private customer data, or production secrets into a translation request ([here's how to redact before you send](https://wurk.fun/blog/keep-personal-data-out-of-your-llm-prompts-redact-before-you-send)).

Give the translator enough context to distinguish a button label from a sentence. Include a glossary for your product name and terms that must remain in English. Add examples from your app so the wording stays consistent across batches.

Use this prompt, replacing the bracketed sections:

```
Translate the JSON string values into [target language and locale].

Context: [what the app does and who uses it]
Glossary: [product name and preferred terms]
Do not translate: [brand names, commands, or other fixed terms]

Rules:
- Return valid JSON only, with exactly the same keys.
- Do not translate or rename keys or runtime argument names.
- Preserve placeholders such as {name}; move them if grammar needs it.
- Preserve HTML tags and attributes; do not invent links.
- Keep button labels concise without changing their meaning.
- For ICU messages, preserve argument names and syntax. Use the
  plural forms needed by the target locale, including "other".
- Do not leave values empty. Flag uncertainty separately instead
  of guessing; do not put comments inside the JSON.

JSON:
[paste one batch here]
```

If you want the uncertain strings listed, ask for that list in a follow-up message, so the JSON stays clean. Save and check the batch before moving on. Never silently fill a missing string with a guess.

## Treat plurals as messages, not word swaps

ICU MessageFormat can select text based on a number with `plural`, or choose among named cases with `select`. A plural message might look like this:

```
{count, plural, one {# file} other {# files}}
```

Here, `count` is an argument name, `one` and `other` are selectors, and `#` represents the number in the plural message. The translated wording belongs inside the branches; the argument and formatting syntax must remain usable. ICU's guide explains the structure and requires an `other` branch ([ICU message formatting](https://unicode-org.github.io/icu/userguide/format_parse/messages)).

Don't assume that a target language uses the same plural categories as English. CLDR documents categories such as `one`, `few`, `many`, and `other`; the categories and the numbers they cover vary by language ([CLDR plural rules](https://cldr.unicode.org/index/cldr-spec/plural-rules)).

That means "keep the same placeholders" needs care. Preserve argument names and their purpose, but don't force the target message to have exactly the same plural branches as the source. The target may need different branches for natural grammar.

Use your app's actual ICU parser or formatter to validate each translated pattern. Compare argument names and types with the source, then format representative values for every relevant target-language category. Have a speaker of that language check the resulting sentences. A syntactically valid message can still say the wrong thing.

## Run a check after every batch

The following Python script checks **flat JSON files with simple `{name}`-style placeholders**. It compares keys and placeholder counts, rejects empty values, and stops on brace syntax it cannot handle. It is not an ICU parser or an HTML validator.

Save it as `check_strings.py`. Compare each translated batch against the matching source batch. If a coding agent is doing the translating, tell it to run this after every batch and fix what it reports before it moves on; if you want a harness where the agent can run scripts like this itself, you can [try the zcode agent harness free](https://zcode.z.ai/invite/ALWM9JUA).

```
python check_strings.py source.json translated.json
```

```python
import json
import re
import sys
from collections import Counter

TOKEN = re.compile(r"\{[A-Za-z_][A-Za-z0-9_]*\}")

def no_duplicates(pairs):
    result = {}
    for key, value in pairs:
        if key in result:
            raise ValueError(f"Duplicate key: {key}")
        result[key] = value
    return result

def load(path):
    with open(path, encoding="utf-8") as f:
        data = json.load(f, object_pairs_hook=no_duplicates)
    if not isinstance(data, dict):
        raise ValueError(f"{path}: expected a JSON object")
    return data

def placeholders(text):
    # This checker does not support ICU quoting or complex braces.
    if "'{" in text or "}'" in text:
        raise ValueError("quoted brace syntax needs separate review")
    remainder = TOKEN.sub("", text)
    if "{" in remainder or "}" in remainder:
        raise ValueError("unsupported or malformed brace syntax")
    return Counter(TOKEN.findall(text))

source, target = map(load, sys.argv[1:3])
errors = []

for key in sorted(source.keys() - target.keys()):
    errors.append(f"{key}: missing from translation")
for key in sorted(target.keys() - source.keys()):
    errors.append(f"{key}: extra translation key")

for key in sorted(source.keys() & target.keys()):
    original, translated = source[key], target[key]
    if not isinstance(original, str) or not isinstance(translated, str):
        errors.append(f"{key}: expected string values")
        continue
    if not translated.strip():
        errors.append(f"{key}: empty translation")
    try:
        if placeholders(original) != placeholders(translated):
            errors.append(f"{key}: placeholders differ")
    except ValueError as exc:
        errors.append(f"{key}: {exc}")

if errors:
    print("\n".join(errors))
    sys.exit(1)

print("Simple key and placeholder checks passed.")
```

Fix every reported issue and run it again. A pass covers only the checks described above: it doesn't check translation quality, HTML, ICU, other placeholder styles, or text fit. Don't treat an unsupported message as a pass; send it through the validator for the format your app actually uses.

## Look at the app, then get a human check

Load the translated strings in the app and open the screens where people start, complete a task, encounter an error, and change settings. Use a narrow phone viewport and check long labels, menus, dialogs, and error messages. Tap through: a button that looks fine but hides its action is still a problem.

Try realistic variable values, including a long name. Check that tags wrap the intended words and that links still point where they should. For plural messages, display the representative values you tested with the formatter, not just the default screen.

If the language reads right to left, check direction and layout as well as the translated text. For an HTML page primarily in an RTL language, MDN documents setting `dir="rtl"` on the root element; mixed-direction content may need its own handling ([MDN: dir](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Global_attributes/dir)).

Before release, ask a native speaker to spot-check the main screens in context. Give them screenshots or a test build, plus the glossary and a way to report the key or screen for each issue. Ask whether the wording makes sense, not just whether it is grammatically possible.

Apply their corrections, rerun the checks, and look at the changed screens again. Keep the reviewed target file with the release so you know exactly which version was checked.

## The checklist

- Source file untouched, translations in a separate file
- Small batches, with glossary, context and a do-not-translate list
- Keys, placeholders and tags preserved; plurals use the target language's categories
- `check_strings.py` passes after every batch, and ICU messages go through your app's real parser
- Every main screen opened on a narrow phone viewport, RTL checked if needed
- A native speaker reviewed the screens people use most

A whole language is a lot of batches and re-runs for an agent. If you're choosing a plan for that, there's [10% off GLM coding plans](https://z.ai/subscribe?ic=R0K78RJKNW). There's [more on our blog](https://claw.rommark.dev) about shipping small apps with coding agents.

If this saved you a `{name}` on a customer's screen, a small tip on the post keeps these guides coming.
