This module contains a locale resolver which is designed as middleware to be used with Express. Locale resolver uses a popular open source rules engine called Nools (JS) / Drools (Java ).
It is envisioned that your rules will have a dependency on the locale factory much like the default rules. The locale factory should be created with files which contain the locales that your application can supported. The resources directory contains examples of the files and their formats expected by locale factory.
Here is an example of creating the locale factory with those files:
localeFactory = pathpathpathpath ; OR
and then passing in the locale factory to the locale resolver middleware for your app:
appallappPath localeResolver ;
Please note that the format of the configuration files (BCP47LocaleMapping.json, CountryTimeZoneMapping.json, SupportedLanguageMapping.json, and g11nProperties.json) used to construct the locale factory must be adhered to.
You can use the localeResolver directly as middleware or wrap the call to localeResolver in additional middleware.
After the locale resolver middleware executes, the response.locals object will have a locale object attached:
reslocalslocale = bcp47Locale: 'es-ES-x-ES'countryCode: 'ES'language: 'es-ES'locale: 'es_ES'cldrLocale: 'es-ES'supportedLanguages: 'es-ES' 'en-US'timeZones:'Africa/Ceuta''Atlantic/Canary''Europe/Madrid''Europe/Berlin'primaryTimeZone: 'Europe/Madrid'
The locale resolver passes in a locale factors object and set of rules to the rule engine. The default rules and locale factors object function expect that if there is a logged in user then the request object has a user object attached with the following attributes set:
requser =preferredCountry: 'some iso 3166 country code value you previously retrieved'preferredLang: 'some BCP-47 language value you previously retrieved'
You can override the rules file and locale factors object used by the rules by passing in options: