UtilAdded in v16.1Optional

WR_LIVE_LOCALE

The interface language as a signal, for code that follows a language switch without importing ngwr/i18n.

Usage

provideWrI18n() provides it as WrI18n.locale. An app without i18n does not provide it, so inject it as optional and fall back to LOCALE_ID.

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 wantRead
The language, in an app that has i18ninject(WrI18n).locale
The language, in a library that must not import ngwr/i18nWR_LIVE_LOCALE
The locale dates are written inwrDateLocale() from ngwr/date, which also honours a pinned locale
  • The value is the code the app passes to WrI18n.use(). Intl throws on a code that is not a BCP 47 tag, so guard it when the app names its languages another way.

API

NameDescriptionTypeDefault
WR_LIVE_LOCALEThe interface language of provideWrI18n(), the signal WrI18n.locale. Not provided without provideWrI18n().InjectionToken<Signal<string>>-

See also