Context-Specific Translations
What you'll learn: How to manage words that mean different things in different parts of your application using translation key suffixes or separate namespaces.
The Problem: Same Word, Different Meanings
In many applications, the same word can have completely different meanings depending on where it appears. For example, "Close" might mean:
- "Close this window" (action button)
- "Close the account" (destructive action)
- "Close to completion" (status indicator)
If you use a single translation key like close everywhere, translators have no context, and translations may be ambiguous or incorrect. In German, these might be "Schließen," "Kündigen," and "Nahe" respectively—completely different words.
Solution: Disambiguate with Context
There are two main approaches:
1. Key Suffixes
Add context directly to your translation keys:
// Instead of reusing "close"
t('close.button') // "Close" (close window)
t('close.account') // "Close Account" (destructive)
t('close.status') // "Close" (proximity)
2. Namespace Separation
Group translations by feature or component:
t('dialog.close') // Dialog-specific close
t('account.close') // Account-specific close
t('progress.close') // Progress-related close
Both approaches give translators the context they need to choose the right translation, and you avoid unintended reuse of ambiguous terms.
When to Use Context-Specific Keys
- Same word appears in different UI areas with different meanings
- Action words that could be destructive vs. benign
- Technical terms with domain-specific meanings
- Formality levels differ (customer-facing vs. internal tools)
Key Takeaway: Use suffixes or namespaces to create context-specific translation keys when the same word has different meanings in different parts of your application, ensuring accurate and appropriate translations.