LangModule

lang. LangModule

Module to handle localisation of language strings

Constructor

new LangModule()

Source:

Extends

  • AbstractModule

Members

phrases :Object

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

supportedLanguages :Array.<String>

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

Methods

addTranslationUtils(req, res, next)

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

getPhrasesForLang(lang) → {Object}

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

(async) init()

Source:

(async) loadPhrases() → {Promise}

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

(async) loadPhrasesForDir(dir) → {Promise}

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

(async) loadRoutes() → {Promise}

Description:
  • Loads the router & routes
Source:
Returns:
Type
Promise

requestHandler(req, res, next)

Description:
  • Shortcut to log a missing language key
Source:
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}

Description:
  • Returns translated language string
Source:
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)

Description:
  • Translates an AdaptError
Source:
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)