Home Reference Source
import {L10N} from 'guide4you/src/L10N.js'
public class | source

L10N

Extends:

ol/Observable~Observable → L10N

This class localizes texts by either selecting one from a dictionary (asynchron loaded JSON File) or choosing the right string from a selection.

Constructor Summary

Public Constructor
public

Member Summary

Public Members
public
Private Members
private
private
private
private

Method Summary

Public Methods
public
public
public
public

isRtl(): bool

public

localiseUsingDictionary(identifier: string, silent: boolean): string

Localise identifier using given dictionary.

public

selectL10N(data: *): string

Select language string.

public
public

Public Constructors

public constructor(options: L10NOptions) source

Params:

NameTypeAttributeDescription
options L10NOptions

Public Members

public dictionary: * source

Private Members

private availableLanguages_: string[] source

private currentLang_: string source

private defaultLang_: string source

private languageFileUrl_: URL source

Public Methods

public getAvailableLanguages(): string[] source

Return:

string[]

public getCurrentLang(): string | * source

Return:

string | *

public getDefaultLang(): * source

Return:

*

public isRtl(): bool source

Return:

bool

public localiseUsingDictionary(identifier: string, silent: boolean): string source

Localise identifier using given dictionary. Throws an error if identifier is not in dictionary. Relies on selectL10N to select actual localisation.

Params:

NameTypeAttributeDescription
identifier string
silent boolean

if an error message should be printed if the text is not found in the dictionary

Return:

string

a (presumably localised) string

public selectL10N(data: *): string source

Select language string. Note that this routine throws an error if there is no fitting string. Method to obtain the fitting string:

  1. If there is no data, an 'Unable to obtain localization' error is thrown.
  2. If data is a string, that string is returned.
  3. If language is given and present in data, the string value for langage is returned.
  4. If the default language is given and present in data, that value is returned.
  5. If the special tag '*' is present in data, that value is returned.
  6. If still no string was found at this point, an 'Unable to obtain localization' error is thrown.

Params:

NameTypeAttributeDescription
data *

Return:

string

a (presumably localised) string

Return Properties:

NameTypeAttributeDescription
data Localizable

public setAvailableLanguages(languages: string[]) source

Params:

NameTypeAttributeDescription
languages string[]

public setCurrentLang(lang: string) source

Params:

NameTypeAttributeDescription
lang string