Classes
- I18n
-
The I18n service class is responsible for managing the application locale. It is used to fetch, store and switch the language. It should be used as a singleton.
- I18nText
-
Custom element for displaying internationalized text.
Functions
Typedefs
-
LocaleOptionInterface :
object
-
Locale Option interface for the language selection.
-
i18nInterface :
object
-
The I18n instance configuration.
I18n
The I18n service class is responsible for managing the application locale. It is used to fetch, store and switch the language. It should be used as a singleton.
Kind: global class
-
I18n
- new I18n(config)
-
instance
- ._defaultConfig
- .defaultLocale
-
._config :
i18nInterface
- .setConfig(config)
-
.initialize() ⇒
Promise.<unknown>
-
.getLocaleOptions() ⇒
Record.<string, LocaleOptionInterface>
-
.getLocale() ⇒
string
-
.getURLocale() ⇒
string
-
.preprocessLocale(locale) ⇒
string
-
.setLocale(locale) ⇒
Promise.<Response>
-
.fetchLanguage(locale) ⇒
Promise.<Response>
- .handleFetchPayload(locale, payload)
-
.changeLocale(locale) ⇒
Promise.<Response>
- .setDefaultLocale()
- .storeLocale(locale)
-
.getStoredLocale() ⇒
string
-
.supportsLocale(locale, options) ⇒
boolean
-
static
-
.getInstance() ⇒
I18n
-
.get(path, includeCommon) ⇒
Record.<string, unknown>
-
.getPayload(path, payload) ⇒
Record.<string, unknown>
-
.getDefaultPayload(path, payload) ⇒
Record.<string, unknown>
- .addCommonPayload(payload, path)
-
.getInstance() ⇒
new I18n(config)
Set the configuration for the service.
Param | Type |
---|---|
config | i18nInterface |
i18n._defaultConfig
Kind: instance property of I18n
Properties
Name | Type | Description |
---|---|---|
_defaultConfig | i18nInterface |
The default config. |
i18n.defaultLocale
Kind: instance property of I18n
Properties
Name | Type | Description |
---|---|---|
defaultLocale | string |
The default application locale. |
i18nInterface
i18n._config : Kind: instance property of I18n
i18n.setConfig(config)
Set the configuration for the service.
Kind: instance method of I18n
Param | Type |
---|---|
config | i18nInterface |
Promise.<unknown>
i18n.initialize() ⇒ Initializes the service.
Kind: instance method of I18n
Record.<string, LocaleOptionInterface>
i18n.getLocaleOptions() ⇒ Returns the locale options.
Kind: instance method of I18n
string
i18n.getLocale() ⇒ Returns the locale String.
Kind: instance method of I18n
string
i18n.getURLocale() ⇒ Returns the locale value in the URL query string.
Kind: instance method of I18n
string
i18n.preprocessLocale(locale) ⇒ Normalizes a locale string.
Kind: instance method of I18n
Param | Type |
---|---|
locale | string |
Promise.<Response>
i18n.setLocale(locale) ⇒ Sets the locale.
Kind: instance method of I18n
Param | Type |
---|---|
locale | string |
Promise.<Response>
i18n.fetchLanguage(locale) ⇒ Fetches the language payload from the server.
Kind: instance method of I18n
Param | Type |
---|---|
locale | string |
i18n.handleFetchPayload(locale, payload)
Handles receipt of the language payload from the server.
Kind: instance method of I18n
Param | Type |
---|---|
locale | string |
payload | Record.<string, any> |
Promise.<Response>
i18n.changeLocale(locale) ⇒ User action for changing locale.
Kind: instance method of I18n
Param | Type |
---|---|
locale | * |
i18n.setDefaultLocale()
Sets the locale to the defaultLocale.
Kind: instance method of I18n
i18n.storeLocale(locale)
Saves the language in the local storage.
Kind: instance method of I18n
Param | Type |
---|---|
locale | string |
string
i18n.getStoredLocale() ⇒ Returns the language from local storage.
Kind: instance method of I18n
boolean
i18n.supportsLocale(locale, options) ⇒ Checks if the given locale is supported by checking against localeOptions.
Kind: instance method of I18n
Param | Type |
---|---|
locale | string |
options | Array.<LocaleOptionInterface> |
I18n
I18n.getInstance() ⇒ Returns the instance of the I18n service.
Kind: static method of I18n
Record.<string, unknown>
I18n.get(path, includeCommon) ⇒ Gets an entry from the current language payload given a path.
Kind: static method of I18n
Param | Type | Default |
---|---|---|
path | string |
|
includeCommon | boolean |
true |
Record.<string, unknown>
I18n.getPayload(path, payload) ⇒ Gets the locale payload given a path.
Kind: static method of I18n
Param | Type |
---|---|
path | string |
payload | Record.<string, unknown> |
Record.<string, unknown>
I18n.getDefaultPayload(path, payload) ⇒ The default locale payload.
Kind: static method of I18n
Param | Type |
---|---|
path | string |
payload | Record.<string, unknown> |
I18n.addCommonPayload(payload, path)
Adds the 'common' payload to the requested item payload.
Kind: static method of I18n
Param | Type |
---|---|
payload | Record.<string, unknown> |
path | string |
I18nText
Custom element for displaying internationalized text.
Kind: global class
-
I18nText
-
instance
-
.i18n :
I18n
- .render()
-
.getReplacements() ⇒
Array
-
.doReplacements(text, replacements) ⇒
string
-
.i18n :
-
static
-
.observedAttributes ⇒
Array.<string>
-
.observedAttributes ⇒
-
instance
I18n
i18nText.i18n : Kind: instance property of I18nText
i18nText.render()
Renders the text.
Kind: instance method of I18nText
Array
i18nText.getReplacements() ⇒ Retrieves the replacements from the 'replacements' attribute.
Kind: instance method of I18nText
Returns: Array
- Array of replacement key-value pairs.
string
i18nText.doReplacements(text, replacements) ⇒ Replaces the placeholders in the text with the given replacements.
Kind: instance method of I18nText
Returns: string
- The text with the replacements.
Param | Type | Description |
---|---|---|
text | string |
The text to replace the placeholders in. |
replacements | Array |
Array of replacement key-value pairs. |
Array.<string>
I18nText.observedAttributes ⇒ Defines the observed attributes for the element.
Kind: static property of I18nText
Returns: Array.<string>
- Array of observed attribute names.
signal - Emits a signal.(signalName, payload)
Kind: global function
Param | Type | Description |
---|---|---|
signalName | string |
|
payload | unknown |
The payload to send with the signal. |
listen - Listens for a signal.(signalName, callback)
Kind: global function
Param | Type | Description |
---|---|---|
signalName | string |
The signal to listen for. |
callback | function |
The callback function. |
object
LocaleOptionInterface : Locale Option interface for the language selection.
Kind: global typedef
Properties
Name | Type | Description |
---|---|---|
label | string |
The label for the language. |
value | string |
The value for the language. |
[flag] | string |
The flag for the language. |
[icon] | string |
The icon for the language. |
[country] | string |
The country for the language. |
[language] | string |
The language for the language. |
[file] | string |
The file for the language. |
object
i18nInterface : The I18n instance configuration.
Kind: global typedef
Properties
Name | Type | Description |
---|---|---|
[payload] | Record.<string, unknown> |
The language payload. |
[locale] | string |
The currently selected language code. |
[defaultLocale] | string |
The default language code. |
[path] | string |
The path to the language files. |
localeOptions | Record.<string, LocaleOptionInterface> |
Default locale list for user selection. |
[urlParam] | string |
The URL parameter for the language. |