npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@arpadroid/i18n

v1.0.3

Published

Internationalization module

Downloads

5

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

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.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. |