LangModule

lang. LangModule

Module to handle localisation of language strings

Constructor

new LangModule()

Source:

Extends

  • AbstractModule

Members

phrases :Object

Source:
The loaded language phrases to be used for translation
Type:
  • Object

supportedLanguages :Array.<String>

Source:
Returns the languages supported by the application
Type:
  • Array.<String>

Methods

addTranslationUtils(req, res, next)

Source:
Adds a translate function to incoming API requests for generating language strings in the original request's supported language
Parameters:
Name Type Description
req external:ExpressRequest
res external:ExpressResponse
next function

getPhrasesForLang(lang) → {Object}

Source:
Load all lang phrases for a language
Parameters:
Name Type Description
lang String The language of strings to load
Returns:
The phrases
Type
Object

(async) init()

Source:

(async) loadPhrases() → {Promise}

Source:
Loads, validates and merges all defined langage phrases
Returns:
Type
Promise

(async) loadPhrasesForDir(dir) → {Promise}

Source:
Load all lang phrases for a given directory
Parameters:
Name Type Description
dir String Directory to search
Returns:
Resolves with the phrases
Type
Promise

(async) loadRoutes() → {Promise}

Source:
Loads the router & routes
Returns:
Type
Promise

requestHandler(req, res, next)

Source:
Shortcut to log a missing language key
Parameters:
Name Type Description
req external:ExpressRequest The client request object
res external:ExpressResponse The server response object
next function The callback function

translate(lang, key, data) → {String}

Source:
Returns translated language string
Parameters:
Name Type Description
lang String The target language (if undefined, the default server language will be used)
key String | AdaptError The unique string key (if an AdaptError is passed, the error data will be used for the data param)
data Object Dynamic data to be inserted into translated string
Returns:
Type
String

translateError(lang, error)

Source:
Translates an AdaptError
Parameters:
Name Type Description
lang String The target language
error AdaptError Error to translate
Returns:
The translated error (if passed error is not an instance of AdaptError, the original value will be returned)