Read and switch the locale
Show which locale your app runs in, and change language without restarting, for the strings that allow it. This builds on Internationalization.
Read the current locale
Inject LynxLocale for the locale as a signal:
locale() returns appLocale as the host app sent it. Without one, it returns sourceLocale, then en-US.
Angular's pipes use LOCALE_ID instead. It also falls back when Angular has no data for appLocale (see Set up).
To format dates, numbers or currency for a locale other than en-US, register its data with registerLocaleData().
Switch language while the app runs
A $localize string inside a computed() can switch live. Make it depend on a signal, then replace the translations and change the signal:
These keep the language the app started with:
- template
i18ntext $localizestrings outside acomputed()LOCALE_ID
To change those, the app has to start again with the new appLocale.
Related
- Internationalization
- Use
Intl - Locale API reference
- Pass data from your native app: setting GlobalData such as
appLocale
