The localization service for a Viewer.

See @xeokit/sdk/locale for usage.

Constructors

  • Constructs a LocaleService.

    Parameters

    • cfg: { locale?: string; messages?: any } = ...

      LocaleService configuration

      • Optionallocale?: string

        Initial locale

      • Optionalmessages?: any

        Set of locale translations

    Returns LocaleService

Accessors

  • get locales(): string[]
  • Gets the list of available locales.

    These are derived from the currently configured set of translations.

    Returns string[]

    The list of available locales.

  • set messages(messages: { [key: string]: any }): void
  • Replaces the current set of locale translations.

    • Fires an "updated" event when done.
    • Automatically refreshes any plugins that depend on the translations.
    • Does not change the current locale.
    viewer.localeService.setMessages({
    messages: {
    "en": { // English
    "NavCube": {
    "front": "Front",
    "back": "Back",
    "top": "Top",
    "bottom": "Bottom",
    "left": "Left",
    "right": "Right"
    }
    },
    "mi": { // Māori
    "NavCube": {
    "front": "Mua",
    "back": "Tuarā",
    "top": "Runga",
    "bottom": "Raro",
    "left": "Mauī",
    "right": "Tika"
    }
    }
    }
    });

    Parameters

    • messages: { [key: string]: any }

      The new translations.

    Returns void

Methods

  • Clears all locale translations.

    • Fires an "updated" event when done.
    • Does not change the current locale.
    • Automatically refreshes any plugins that depend on the translations, which will cause those plugins to fall back on their internal hard-coded text values, since this method removes all our translations.

    Returns void

  • Loads a new set of locale translations, adding them to the existing translations.

    • Fires an "updated" event when done.
    • Automatically refreshes any plugins that depend on the translations.
    • Does not change the current locale.
    viewer.localeService.loadMessages({
    "jp": { // Japanese
    "NavCube": {
    "front": "前部",
    "back": "裏",
    "top": "上",
    "bottom": "底",
    "left": "左",
    "right": "右"
    }
    }
    });

    Parameters

    • messages: { [key: string]: any } = {}

      The new translations.

    Returns void

  • Translates the given string according to the current locale.

    Returns null if no translation can be found.

    Parameters

    • msg: string

      String to translate.

    • Optionalargs: any

      Extra parameters.

    Returns string

    Translated string if found, else null.

  • Translates the given phrase according to the current locale.

    Returns null if no translation can be found.

    Parameters

    • msg: string

      Phrase to translate.

    • count: number

      The plural number.

    • Optionalargs: any

      Extra parameters.

    Returns string

    String|null Translated string if found, else null.

Events

onUpdated: EventEmitter<LocaleService, string>

Emits an event each time the locale translations have updated.