packages/core/src/lib/services/locale/locale.service.ts
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:
EuiService
Methods |
Accessors |
constructor()
|
| 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 :
|
||||||||
|
Retrieves the state of the locale service. This method is overloaded to allow different ways of accessing the state. Example :
Parameters :
Returns :
Observable<K>
|
| getState | ||||||||
getState(keyOrMapFn?: unknown | string)
|
||||||||
Type parameters :
|
||||||||
|
Example :
If no parameter is provided, the method returns the entire state.
Parameters :
Returns :
Observable<DeepPartial<K>>
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 :
Returns :
Observable<EuiServiceStatus>
|
| updateState | ||||||
updateState(state: DeepPartial
|
||||||
|
This method is used to update the state of the service with a new state.
Parameters :
Returns :
void
|
| updateState | ||||||||
updateState(state: DeepPartial
|
||||||||
Type parameters :
|
||||||||
|
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 :
Returns :
void
|
| previousLocale |
getpreviousLocale()
|
|
Retrieves the previous locale used in the application.
Returns :
string
|
| currentLocale |
getcurrentLocale()
|
|
Retrieves the current locale used in the application.
Returns :
string
|