Locale
The app's locale from the host app, as a signal and as Angular's LOCALE_ID. import { LynxLocale, provideLocale, getLynxAppLocale } from '@blotch/angular-lynx';
Usage
ng generate @blotch/angular-lynx:add-i18n adds provideLocale() for you.
API
provideLocale()
Provides Angular's LOCALE_ID from LynxLocale.locale(), so pipes such as DatePipe and CurrencyPipe format for that locale. A <q> with no lang attribute on or above it draws that locale's quotation marks too (« » in French), as a localized web build's <html lang> makes it.
- Read once.
LOCALE_IDtakes the locale when the app starts. A later change doesn't reformat pipes. - Falls back without locale data. Angular may have no locale data for the locale, or for its language (
frforfr-CA). ThenLOCALE_IDis thesourceLocalefrom yourangular.json, or'en-US', and a warning is logged. Angular's pipes would throw otherwise. - Register the languages you support. The apps from
ng build --platformsend the phone's language, which your app may not support. Register the data of the ones you do withregisterLocaleData(). English always has data.
getLynxAppLocale()
Returns the host's appLocale value without Angular. Use it in main.ts before bootstrapApplication(), where no injector exists yet. For example, choose which translations to load.
- Returns
undefinedoutside Lynx, or when the host sets no locale.
LynxLocale
The current locale as a signal.
LynxLocale.locale
The locale, chosen in this order:
- The
appLocaleglobal value the host app sets, such as'fr-FR'. - The
i18n.sourceLocalefrom yourangular.json. 'en-US'.
Types
None of its own.
Related
- Internationalization: translations and locale-aware formatting.
- Host data
- Angular i18n
