Options
All
  • Public
  • Public/Protected
  • All
Menu
description

This class handles translation keys and persistence of the currently active user language in a browser environment. We highly recommend using the snake_case format for translation keys to avoid keys duplication and invalid keys content.

You can augment and extend this class using protected properties as listed below.

Warning: This class serves as a base for the translations system as used in this software, modifying or extending can potentially break your software. Please, always make sure to check your translation files.

example

Using the Translations class

  const i18n = new Translations();
console.log(i18n.$t('translate_this_key'));
console.log(i18n.translate('translate_this_key'));



Properties

param language

The currently active language (defaults to "en").

param data

The translations dataset (translated keys).

since

v0.1.0

Hierarchy

  • Translations

Index

Constructors

  • Constructs a translations module instance setting the active language to the one as persisted using the storageProvider property.

    Note that if you are using a forward predicate, make sure to always return ISO-639-1:2002 compliant language codes or the i18n features may break.

    access

    public

    Parameters

    • language: string = "en"

      The currently active language.

    Returns Translations

Properties

data: TranslationDataset = ...
language: string

The currently active language (defaults to "en").

var

{string}

defaultLanguage: string = "en"

The default language to use if none was persisted by the user before (defaults to "en").

static
var

{string}

storageKey: string = "@dhealthdapps/frontend::language"

The default storage key as used by the persistence layer to store the active language.

static
var

{string}

Methods

  • $t(translationKey: string, parameters?: any, customLanguage?: string): string
  • Translation helper method for the active language. This method uses the translations to find the corresponding value for {@param translationKey}.

    A warning will be issued on the console if a translation key is untranslated and requested here.

    access

    public

    Parameters

    • translationKey: string
    • parameters: any = {}
    • Optional customLanguage: string

    Returns string

  • call(translationKey: string, parameters?: any, customLanguage?: string): string
  • Proxy method for $t.

    see

    {Translations.$t}

    access

    public

    Parameters

    • translationKey: string
    • parameters: any = {}
    • Optional customLanguage: string

    Returns string

  • getLanguage(): string
  • translate(translationKey: string, parameters?: any, customLanguage?: string): string
  • Proxy method for $t.

    see

    {Translations.$t}

    access

    public

    Parameters

    • translationKey: string
    • parameters: any = {}
    • Optional customLanguage: string

    Returns string

Generated using TypeDoc