Global

Methods


getLang()

Returns the current language

Returns:
Type
string

getStatus()

Gets the status of the translations

Status is only returned for languages that were loaded (selected language and default language).

Returns:

A map indexed by the language code containing objects with these properties:

  • loading (boolean): True if the language is loading
  • loaded (boolean): True if the language finished loading successfuly
  • failed (boolean): True if there were errors while loading
  • message (String): Error message
Type
object

getStrings()

Returns the string dictionary of the current language

Returns:

A dictionary of strings indexed by string ID

Type
object

init(options)

Initialize the library

Call this method before any others

Parameters:
Name Type Description
options object
  • queryStringVariable (default: 'lang'): Name of the query string variable used to specify the language
    • translationsDirectory (default: 'tr'): Relative path to the directory holding the translations files
    • defaultLanguage (default: 'en'): Default language to use if no query string is specified
    • fallbackToDefaultLanguage (default: true): Use default language when the requested language does not exist or the requested string does not exist in the language.
Returns:

Returns a promise resolved after the translation file is loaded

Type
Promise

loadLang(code)

Loads the specified language into the cache

If the language was previously loaded this method causes a reload.

Parameters:
Name Type Description
code string

Language code

Returns:

Returns a promise resolved after the translation file is loaded

Type
Promise

reset()

Resets the state of loaded translations and configuration


setLang(code, reload)

Sets the current language. The translation will be loaded if it was not previously loaded or if a reload is requested.

Parameters:
Name Type Default Description
code string

Language code

reload boolean false

Reload the translation file

Returns:

Returns a promise resolved after the translation file is loaded

Type
Promise

t(stringID)

Returns a string translated to the current language

If the string ID is not found an empty string will be returned

Parameters:
Name Type Description
stringID

ID of the string to translate

Returns:

The translation

Type
string