import { LOCALE_ID, computed, inject } from '@angular/core';
import { WR_LIVE_LOCALE } from 'ngwr/utils';
private readonly live = inject(WR_LIVE_LOCALE, { optional: true });
private readonly fallback = inject(LOCALE_ID);
// Rewritten when the app calls WrI18n.use().
protected readonly price = computed(() =>
new Intl.NumberFormat(this.live?.() ?? this.fallback, { style: 'currency', currency: 'EUR' }).format(this.amount())
);| You want | Read |
|---|---|
| The language, in an app that has i18n | inject(WrI18n).locale |
The language, in a library that must not import ngwr/i18n | WR_LIVE_LOCALE |
| The locale dates are written in | wrDateLocale() from ngwr/date, which also honours a pinned locale |
- The value is the code the app passes to
WrI18n.use().Intlthrows on a code that is not a BCP 47 tag, so guard it when the app names its languages another way.