Outcome Recipes
Outcome-oriented scenarios for @aurelia/i18n covering locale switching, formatting, and validation integration.
1. Locale switcher that persists the user’s preference
Steps
import { I18N } from '@aurelia/i18n'; import { resolve } from '@aurelia/kernel'; export class LocaleService { private readonly i18n = resolve(I18N); private readonly storageKey = 'preferred-locale'; constructor() { const saved = localStorage.getItem(this.storageKey); if (saved) { void this.i18n.setLocale(saved); } } async changeLocale(locale: string) { await this.i18n.setLocale(locale); localStorage.setItem(this.storageKey, locale); } }
Checklist
2. Number and date formatting per locale
Steps
Checklist
3. Validation messages that respect the current locale
Steps
Checklist
4. Lazy-load namespaces per route
Steps
Checklist
5. Relative time formatting
Steps
Checklist
Reference material
Last updated
Was this helpful?