### File

`packages/core/src/lib/services/locale/locale.service.ts`

### Description

LocaleService is responsible for managing locale states and configurations in an Angular application. It utilizes the CLDR library to load and construct the locale for each region. This service allows for dynamic loading of locales upon request and updates the state of the EUI app accordingly.

Key functionalities include:

- Binding to a translation service for locale changes.
- Updating the Angular LOCALE_ID token.

### Extends

`EuiService`

### Index

###### Methods

- getSignal
- getState
- getState
- getState
- getState
- init
- updateState
- updateState

###### Accessors

- previousLocale
- currentLocale

### Constructor

`constructor(store: StoreService, baseGlobalConfig: GlobalConfig, locale_id: string, localeMapper: LocaleMapper, i18n: I18nService, log: LogService)`

Parameters :

Name | Type | Optional
store | `StoreService` | No
baseGlobalConfig | `GlobalConfig` | No
locale_id | `string` | No
localeMapper | `LocaleMapper` | No
i18n | `I18nService` | No
log | `LogService` | No

### Methods

getSignal
`getSignal()`
This method is used to get the state as readonly signal. Returns : `Signal<T>`

getState
`getState()`
Returns : `Observable<T>`

getState
`getState(mapFn?: (state?: T) => void)`

Type parameters :

- K

Retrieves the state of the locale service. This method is overloaded to allow different ways of accessing the state.

Example :

                                     Takes the current state as an argument and returns the transformed state.

Parameters :

Name | Type | Optional | Description

mapFn

`function`

Yes

- A function that maps the state to a specific form. Takes the current state as an argument and returns the transformed state.

Returns : `Observable<K>`

- An observable that emits the transformed state.

getState
`getState(key?: a)`

Type parameters :

- a

Example :

                   The key should be a property name of the state object.

Parameters :

Name | Type | Optional | Description

key

`a`

Yes

- A specific key to access a part of the state. The key should be a property name of the state object.

Returns : `Observable<DeepPartial<a>>`

- An observable that emits the value of the specified key in the state.

getState
`getState(keyOrMapFn?: | string)`

Type parameters :

- K

Example :

                                                   If a string is provided, it uses dot notation to access nested properties.

If no parameter is provided, the method returns the entire state.

Parameters :

Name | Type | Optional | Description

keyOrMapFn

`| string`

Yes

- Either a mapping function or a string key. If a string is provided, it uses dot notation to access nested properties.

Returns : `Observable<DeepPartial<K>>`

- An observable that emits the selected or transformed state.

If no parameter is provided, the method returns the entire state.

init
`init(state?: LocaleState)`

Initializes the LocaleService with necessary configurations and state. Binds language changes to the state and dynamically loads the appropriate locales.

Parameters :

Name | Type | Optional | Description

state

`LocaleState`

Yes

- Optional initial state for the locale service.

Returns : `Observable<EuiServiceStatus>`

- Observable emitting the status of the initialization.

updateState
`updateState(state: DeepPartial<T>)`

This method is used to update the state of the service with a new state.

Parameters :

Name | Type | Optional
state | `DeepPartial<T>` | No

Returns : `void`

updateState
`updateState(state: DeepPartial<K>)`

Type parameters :

- K

Updates the locale state within the application. If the new state is not available, it throws an error. Also updates the global LOCALE_ID token if configured to do so.

Parameters :

Name | Type | Optional | Description

state

`DeepPartial<K>`

No

- The new state to be set for the locale.

Returns : `void`

### Accessors

previousLocale
get `previousLocale()`
Retrieves the previous locale used in the application. Returns : `string`

currentLocale
get `currentLocale()`
Retrieves the current locale used in the application. Returns : `string`

# results matching ""

# No results matching ""