Guides

Validate AI-Translated UI Strings Before Shipping a New Locale

Catch missing placeholders and stale UI translations with a small JavaScript check, then review how the translated string renders.

Key takeaway

Block structural mistakes automatically and review meaning in the rendered interface before releasing a translation.

On this page
  1. Reject a broken string before review
  2. Review meaning inside the interface

A fluent translation can still break a real screen. A message such as “Welcome, {name}. You have {count} reports.” needs both variables to survive translation, and a previously approved translation needs review when its English source changes. OpenRouter’s November 12 localization write-up describes checking strings in code and tracking changes against the English source. Here is a small way to apply those checks to a product you maintain. OpenRouter engineering write-up

Reject a broken string before review

For a project whose placeholders are simple names in braces, compare the sorted list of occurrences. Sorting lets the translator reorder variables, while counting every occurrence catches a dropped duplicate. This example also keeps a copy of the source the translator saw.

function placeholders(text) {
  return Array.from(text.matchAll(/\{([A-Za-z_][A-Za-z0-9_]*)\}/g),
    match => match[1]).sort().join(",");
}

function check(source, translatedFrom, translation) {
  if (source !== translatedFrom) return "stale source";
  if (placeholders(source) !== placeholders(translation)) {
    return "placeholder mismatch";
  }
  return "ready for language review";
}

const source = "Welcome, {name}. You have {count} reports.";
const good = "Vous avez {count} rapports, {name}.";
console.log(check(source, source, good));
console.log(check(source, source, "Bonjour, {name}."));
console.log(check(source + " Open the archive.", source, good));

The example prints ready for language review, placeholder mismatch, and stale source. In a larger catalog, store a source fingerprint per key or use your localization tool’s source-equivalence mechanism. Revalidate against the current source before accepting a translation from a queue.

Use your actual message parser for ICU plural branches, escaped tokens, rich text or other structured placeholders. A brace pattern only covers the simple syntax shown here. For a pluralized string, compare the parsed structure under your localization format and inspect the target language’s required forms.

Review meaning inside the interface

Render one long name and the smallest and largest counts your UI expects. Check where the message wraps and whether the action or error stays clear next to its button. Give reviewers the UI label and surrounding screen context with each string so they can resolve ambiguous words such as “archive” or “draft.” Keep the prior reviewed release available while resolving failures in the new locale.

Verification on November 17. We ran the sample with Node.js and checked reordered variables, a missing variable, a repeated variable, and an edited source. The French text is an authored fixture.

Sources & references

Written by Modelrovia Editorial. Our standards distinguish official claims from observed results.

How we research and test →