Module: libs/locales

libs/locales

This module exposes the locale-determination logic for resource bundles implementation that needs to produce localized messages.

Version:
  • 1.0

Requires

  • module:./locales/accept-rules.json

Members

defLocaleString

Default language code

errorFilesObject

Collection of expections during parsering the locale files, where key is file name and value is error object.

localeMapObject

Collection of localization objects where key points to locale code and value map of key and value of localization messages.

Methods

config(appconf)

This method executed once reading locales setting defined in appconf.json and building tree of locale messages localeMap at start time.

Name Type Description
appconf Object

JSON object represents application configuration.

Example

conf/app.json { ... "locales": { "default": "en-us", "path": "/src/locales" } ... }

init(req, locale){Object}

Initializing current user locale and returning locallization map of localized messages.

Name Type Description
req express.Request

Defines an object to provide client request information.

locale String optional

User language code.

Returns:
Collection of localization messages.

protectedlocalelookup(localeDir)

Traverse all locales files under locale directory.

Name Type Description
localeDir String

Absolute path to locale directory.

protectedsaveToSession(req, locale)

Save current language code into express.Request session.

Name Type Description
req express.Request

Defines an object to provide client request information.

locale String

User language code.

protectedsetLocale(req, locale)

Determine user language code base on URL parameter or browser language settings.

Name Type Description
req express.Request

Defines an object to provide client request information.

locale String optional

User language code.