Namespace: I18n

PSPDFKit.I18n

Namespace for the internationalization and localization (i18n) configuration. The current locale can be retrieved via PSPDFKit.Instance#locale, and set with PSPDFKit.Instance#setLocale.

Members

Methods




Members

(static) locales

Returns an array of available locales. Each entry in the array is a string representing the locale e.g. en. The array can be mutated directly to add new locales. Note that when adding new locales you also need to add the corresponding translated messages.

Example

Add a new locale.

PSPDFKit.I18n.locales.push("fr");

(static) messages

Returns an object containing the translated messages for every locale. In the messages object each key represents the locale and values are objects containing messageId-translated message pairs.

The messages object can be mutated directly to change translations or add new ones.

Examples

The messages object

{
  "en": {
    "delete": "Delete",
    "openPDF": "Open PDF"
  },
  "it": {
    "delete": "Rimuovi",
    "openPDF": "Apri PDF"
  }
}

Mutate the messages object. Replace "Open PDF" with "Open".

PSPDFKit.I18n.messages.en.openPDF = "Open";

Methods

(static) preloadLocalizationData(locale, optionsopt) → {Promise}

PSPDFKit for Web comes with a number of predefined locales which are loaded automatically on demand when using the PSPDFKit.Instance#setLocale API or when setting a locale in the main PSPDFKit.Configuration.

The locale information are then exposed to PSPDFKit.I18n.messages.

You can use this method to preload these information instead of loading them on demand. This would allow you to modify some translations before loading PSPDFKit for Web for example.

Parameters:
Name Type Attributes Description
locale string

The locale to load the localization data for.

options object <optional>
Properties
Name Type Attributes Description
baseUrl string <optional>

The location of the pspdfkit-lib directory. See PSPDFKit.Configuration#baseUrl.

Returns:

void Returns a promise that resolves when the locale data have been loaded.

Type
Promise