1.0.3 • Published 1 year ago

@arpadroid/i18n v1.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

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

new I18n(config)

Set the configuration for the service.

ParamType
configi18nInterface

i18n._defaultConfig

Kind: instance property of I18n
Properties

NameTypeDescription
_defaultConfigi18nInterfaceThe default config.

i18n.defaultLocale

Kind: instance property of I18n
Properties

NameTypeDescription
defaultLocalestringThe 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

ParamType
configi18nInterface

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

ParamType
localestring

i18n.setLocale(locale) ⇒ Promise.<Response>

Sets the locale.

Kind: instance method of I18n

ParamType
localestring

i18n.fetchLanguage(locale) ⇒ Promise.<Response>

Fetches the language payload from the server.

Kind: instance method of I18n

ParamType
localestring

i18n.handleFetchPayload(locale, payload)

Handles receipt of the language payload from the server.

Kind: instance method of I18n

ParamType
localestring
payloadRecord.<string, any>

i18n.changeLocale(locale) ⇒ Promise.<Response>

User action for changing locale.

Kind: instance method of I18n

ParamType
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

ParamType
localestring

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

ParamType
localestring
optionsArray.<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

ParamTypeDefault
pathstring
includeCommonbooleantrue

I18n.getPayload(path, payload) ⇒ Record.<string, unknown>

Gets the locale payload given a path.

Kind: static method of I18n

ParamType
pathstring
payloadRecord.<string, unknown>

I18n.getDefaultPayload(path, payload) ⇒ Record.<string, unknown>

The default locale payload.

Kind: static method of I18n

ParamType
pathstring
payloadRecord.<string, unknown>

I18n.addCommonPayload(payload, path)

Adds the 'common' payload to the requested item payload.

Kind: static method of I18n

ParamType
payloadRecord.<string, unknown>
pathstring

I18nText

Custom element for displaying internationalized text.

Kind: global class

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.

ParamTypeDescription
textstringThe text to replace the placeholders in.
replacementsArrayArray 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

ParamTypeDescription
signalNamestring
payloadunknownThe payload to send with the signal.

listen - Listens for a signal.(signalName, callback)

Kind: global function

ParamTypeDescription
signalNamestringThe signal to listen for.
callbackfunctionThe callback function.

LocaleOptionInterface : object

Locale Option interface for the language selection.

Kind: global typedef
Properties

NameTypeDescription
labelstringThe label for the language.
valuestringThe value for the language.
flagstringThe flag for the language.
iconstringThe icon for the language.
countrystringThe country for the language.
languagestringThe language for the language.
filestringThe file for the language.

i18nInterface : object

The I18n instance configuration.

Kind: global typedef
Properties

NameTypeDescription
payloadRecord.<string, unknown>The language payload.
localestringThe currently selected language code.
defaultLocalestringThe default language code.
pathstringThe path to the language files.
localeOptionsRecord.<string, LocaleOptionInterface>Default locale list for user selection.
urlParamstringThe URL parameter for the language.
1.0.2

1 year ago

1.0.3

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago