L18n

L18n Simple internationalization logic

Constructor

new L18n(appInstance)

Constructor

Parameters:
NameTypeDescription
appInstanceApp

InfrontJS App reference

Methods

addTranslation(langCode, translationObject)

Add given translation object to dictionary

Parameters:
NameTypeDescription
langCodestring

Langugae code (2 chars)

translationObjectobject

The translation object, simple key-value object, e.g. { 'Hello' : 'Hallo' }

expose()

Export localization functions to window scope.

getCurrentLanguage() → {string}

Get current selected language

Returns:
  • Returns 2 chared language code
Type: 
string

getDateTime(dt, optsopt) → {string}

Get formatted date time

Parameters:
NameTypeAttributesDefaultDescription
dtDate

Date object to format

optsObject<optional>
null

DateTimeFormat options used if set. @see DateTimeFormat

Returns:
Type: 
string

getLocale(key, paramsopt) → {string}

Gets current translation by given key

Parameters:
NameTypeAttributesDescription
keystring

Translation key

paramsarray<optional>

Params array

Returns:
Type: 
string

getNumber(num, optsopt) → {string}

Get formatted number

Parameters:
NameTypeAttributesDefaultDescription
numDate0

Number to format

optsObject<optional>
null

NumberFormat options used if set. @see NumberFormat

Returns:
Type: 
string

resolveBrowserLanguage() → {*|null|string}

Resolve preferred browser language

Returns:
Type: 
* | null | string

setCurrentLanguage(langCode)

Set current language

Parameters:
NameTypeDescription
langCodestring

2 chared language code

Throws:
  • Invalid language code
Type
Error

setDictionary(dictopt)

Sets dictionary

Parameters:
NameTypeAttributesDefaultDescription
dictobject<optional>
{ defaultLang : { "langCode" : "translation", ... }, ... }

Dictionary