@arpadroid/i18n
v1.0.3
Published
Internationalization module
Downloads
5
Maintainers
Readme
Classes
Functions
Typedefs
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)
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. |
i18n._config : i18nInterface
Kind: instance property of I18n
i18n.setConfig(config)
Set the configuration for the service.
Kind: instance method of I18n
| Param | Type | | --- | --- | | config | i18nInterface |
i18n.initialize() ⇒ Promise.<unknown>
Initializes the service.
Kind: instance method of I18n
i18n.getLocaleOptions() ⇒ Record.<string, LocaleOptionInterface>
Returns the locale options.
Kind: instance method of I18n
i18n.getLocale() ⇒ string
Returns the locale String.
Kind: instance method of I18n
i18n.getURLocale() ⇒ string
Returns the locale value in the URL query string.
Kind: instance method of I18n
i18n.preprocessLocale(locale) ⇒ string
Normalizes a locale string.
Kind: instance method of I18n
| Param | Type | | --- | --- | | locale | string |
i18n.setLocale(locale) ⇒ Promise.<Response>
Sets the locale.
Kind: instance method of I18n
| Param | Type | | --- | --- | | locale | string |
i18n.fetchLanguage(locale) ⇒ Promise.<Response>
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> |
i18n.changeLocale(locale) ⇒ Promise.<Response>
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 |
i18n.getStoredLocale() ⇒ string
Returns the language from local storage.
Kind: instance method of I18n
i18n.supportsLocale(locale, options) ⇒ boolean
Checks if the given locale is supported by checking against localeOptions.
Kind: instance method of I18n
| Param | Type | | --- | --- | | locale | string | | options | Array.<LocaleOptionInterface> |
I18n.getInstance() ⇒ I18n
Returns the instance of the I18n service.
Kind: static method of I18n
I18n.get(path, includeCommon) ⇒ Record.<string, unknown>
Gets an entry from the current language payload given a path.
Kind: static method of I18n
| Param | Type | Default | | --- | --- | --- | | path | string | | | includeCommon | boolean | true |
I18n.getPayload(path, payload) ⇒ Record.<string, unknown>
Gets the locale payload given a path.
Kind: static method of I18n
| Param | Type | | --- | --- | | path | string | | payload | Record.<string, unknown> |
I18n.getDefaultPayload(path, payload) ⇒ Record.<string, unknown>
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
- static
- .observedAttributes ⇒ Array.<string>
- instance
i18nText.i18n : I18n
Kind: instance property of I18nText
i18nText.render()
Renders the text.
Kind: instance method of I18nText
i18nText.getReplacements() ⇒ Array
Retrieves the replacements from the 'replacements' attribute.
Kind: instance method of I18nText
Returns: Array - Array of replacement key-value pairs.
i18nText.doReplacements(text, replacements) ⇒ string
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. |
I18nText.observedAttributes ⇒ Array.<string>
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. |
LocaleOptionInterface : object
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. |
i18nInterface : object
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. |