Prompt
How do I prevent broken UI from bad translations?
Latest observation
To prevent broken UI from bad translations, build for translation resilience rather than assuming every string will be well-formed. Here are the most effective practices:
1. Use placeholders, not string concatenation
Bad translations often break when code builds sentences like "Hello " + name + "!".
Use parameterized strings instead:
- English:
"Hello, {name}!" - Other languages can reorder words safely.
2. Support pluralization and gender properly
Don’t hardcode 1 item vs 2 items. Use i18n features that handle:
- singular/plural
- zero forms
- gender
- case/inflection
3. Design UI for text expansion
Translations are often longer than English.
- Allow buttons and labels to grow
- Avoid fixed-width containers when possible
- Use flexible layouts and wrapping
- Test with long pseudo-localized strings
4. Avoid embedding HTML in translations
If translators can change markup, they may break layout or introduce security issues.
- Keep markup in code where possible
- Use safe interpolation for dynamic content
5. Validate translation files
Run automated checks for:
- missing keys
- extra/mismatched placeholders
- invalid ICU syntax
- broken escape sequences
- untranslated fallback strings
6. Use a linter or compiler for translations
Prefer translation systems that compile or validate messages at build time, so mistakes fail early rather than in production.
7. Add pseudo-localization tests
Pseudo-localization helps catch UI issues before real translations:
- expand text by 30–40%
- add accented characters
- use RTL-like direction in testing
- insert brackets around strings to reveal truncation
8. Test right-to-left languages
Make sure your UI handles:
- RTL layout mirroring
- mixed LTR/RTL text
- icons/arrows that should flip
- date/number formatting
9. Provide safe fallbacks
If a translation is missing or invalid:
- show the default language string
- log the problem
- avoid rendering empty or malformed UI
10. Involve translators with context
Give translators:
- screenshots
- character limits
- explanation of where text appears
- notes for variables and tone
This reduces mistranslations that break the interface.
Good rule of thumb
Assume every translation can be:
- longer
- shorter
- reordered
- missing a placeholder
- right-to-left
- poorly formatted
So your UI should remain usable even when the translation is imperfect.
If you want, I can also give you:
- a translation validation checklist,
- examples for React/i18next, or
- a CI test setup to catch bad translations automatically.