> For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt.

# 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

```typescript title="src/app/app.config.ts"
import { type ApplicationConfig } from '@angular/core';
import { provideLocale, provideRenderer } from '@blotch/angular-lynx';

export const appConfig: ApplicationConfig = {
  providers: [provideRenderer(), provideLocale()],
};
```

`ng generate @blotch/angular-lynx:add-i18n` adds `provideLocale()` for you.

## API

### `provideLocale()`

```typescript
function provideLocale(): EnvironmentProviders;
```

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_ID` takes 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 (`fr` for `fr-CA`). Then `LOCALE_ID` is the `sourceLocale` from your `angular.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 --platform` send the phone's language, which your app may not support. Register the data of the ones you do with [`registerLocaleData()`](https://angular.dev/api/common/registerLocaleData). English always has data.

### `getLynxAppLocale()`

```typescript
function getLynxAppLocale(): string | undefined;
```

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 `undefined`** outside Lynx, or when the host sets no locale.

```typescript title="src/main.ts"
import { loadTranslations } from '@angular/localize';
import { bootstrapApplication, getLynxAppLocale } from '@blotch/angular-lynx';
import { App } from './app/app';
import { appConfig } from './app/app.config';

if (getLynxAppLocale()?.startsWith('fr')) {
  loadTranslations({ greeting: 'Bonjour !' });
}

bootstrapApplication(App, appConfig);
```

### `LynxLocale`

```typescript
@Injectable({ providedIn: 'root' })
class LynxLocale {}
```

The current locale as a signal.

### `LynxLocale.locale`

```typescript
readonly locale: Signal<string>;
```

The locale, chosen in this order:

1. The `appLocale` global value the [host app](/guide/glossary.md#host-app) sets, such as `'fr-FR'`.
2. The `i18n.sourceLocale` from your `angular.json`.
3. `'en-US'`.

## Types

None of its own.

## Related

- [Internationalization](/guide/i18n/index.md): translations and locale-aware formatting.
- [Host data](/api/angular-lynx/host/host-data.md)
- [Angular i18n](https://angular.dev/guide/i18n)
