i18n API
Translation templates and multi-language localization with dynamic substitutions.
What It Does
The i18n API provides a complete translation pipeline for internationalizing applications. It manages translation templates with dynamic variable substitution, integrates with Google Cloud Translation for automatic translation, and caches translations for performance.
Key Capabilities
- Translation Templates: Reusable templates with placeholder variables
- Multi-Language Support: English, Spanish (easily extensible)
- Dynamic Substitution: Insert runtime values into templates
- Translation Caching: Cache translated phrases to avoid redundant API calls
- Google Cloud Translation: Automatic translation via GCP Translation API
- Admin Management: CRUD operations for translation templates
Main Components
I18nService
getLocalizedText(
translatable: ITranslatable,
language: LanguageCode,
substitutions: {...}
): Promise<string>I18nAdminService
setTemplate(model: ITranslationTemplate): Promise<void>
setTemplates(templates: ITranslationTemplate[]): Promise<void[]>
getAllTemplates(): Promise<ITranslationTemplate[]>Template Format
Templates use bracket notation: "Hello [firstName]!"
Data Models
interface ITranslatable {
translationCode: string
substitutionKeys: readonly [...string[]]
}
interface ITranslationTemplate {
id: string // Translation code
englishTemplateString: string // Template with [key] placeholders
}Common Use Cases
- Email templates in multiple languages
- UI text localization
- Notification messages
- Error messages
- Dynamic content with user-specific values
What Customers Don’t Have to Build
- Translation template management
- Google Cloud Translation integration
- Translation caching
- Variable substitution
- Multi-language support
- Template storage and retrieval
Last updated on