Options
All
  • Public
  • Public/Protected
  • All
Menu

Localization service for a Viewer.

Hierarchy

  • LocaleService

Index

Constructors

Accessors

  • get locale(): string
  • set locale(arg: string): void
  • get locales(): string[]
  • set messages(arg: 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.

    Usage

    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

    • arg: any

    Returns void

Methods

  • clearMessages(): void
  • 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

  • fire(event: string, value: any, forget?: boolean): void
  • Fires an event on this LocaleService.

    Notifies existing subscribers to the event, optionally retains the event to give to any subsequent notifications on the event as they are made.

    Parameters

    • event: string

      The event type name.

    • value: any

      The event parameters.

    • Optional forget: boolean

    Returns void

  • loadMessages(messages?: any): 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.

    Usage

    viewer.localeService.loadMessages({
    "jp": { // Japanese
    "NavCube": {
    "front": "前部",
    "back": "裏",
    "top": "上",
    "bottom": "底",
    "left": "左",
    "right": "右"
    }
    }
    });

    Parameters

    • Optional messages: any

      The new translations.

    Returns void

  • off(subId: string): void
  • on(event: string, callback: Function): string
  • on(event: "updated", callback: (e: string | LocaleService) => void): string
  • translate(msg: string, args?: any): null | string
  • Translates the given string according to the current locale.

    Returns null if no translation can be found.

    Parameters

    • msg: string

      String to translate.

    • Optional args: any

    Returns null | string

    Translated string if found, else null.

  • translatePlurals(msg: string, count: number, args?: any): null | string
  • 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.

    • Optional args: any

    Returns null | string

    Translated string if found, else null.

Generated using TypeDoc