Configurable plugin for determine request language in hapi.js applications.
Methods
(static) register(server, options, next)
Hapi plugin function which adds i18n support to request and response objects.
Parameters:
Name | Type | Description |
---|---|---|
server |
Object | Hapi server object |
options |
PluginOptions | Plugin configuration options. |
next |
function | Callback function. |
Type Definitions
PluginOptions
Plugin configuration options.
Type:
- Object
Properties:
Name | Type | Attributes | Default | Description | |||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
locales |
Array.<string> |
<optional> |
[] | List of locales to use in application. |
|||||||||||||||||||||||||
default |
string | null |
<optional> |
1st Locale | Default locale to use if no locale is given. |
|||||||||||||||||||||||||
configFile |
string | null |
<optional> |
package.json | Configuration file to get available locales. |
|||||||||||||||||||||||||
configKey |
string | null |
<optional> |
locales | Key to look in configuration file to get available locales. May be nested key such as 'a.b.c'. |
|||||||||||||||||||||||||
scan |
Object |
<optional> |
Scanning options to get available locales Properties
|
||||||||||||||||||||||||||
param |
string | null |
<optional> |
lang | Name of the path parameter to determine language. ie. /{lang}/account |
|||||||||||||||||||||||||
query |
string | null |
<optional> |
lang | Name of the query parameter to determine language. ie. /account?lang=tr_TR |
|||||||||||||||||||||||||
cookie |
string | null |
<optional> |
lang | Name of the cookie to determine language. |
|||||||||||||||||||||||||
cookieKey |
string | null |
<optional> |
lang | Name of the key to look inside cookie to determine language. May be nested key such as 'a.b.c'. |
|||||||||||||||||||||||||
header |
string | null |
<optional> |
accept-language | Name of the header parameter to determine language. |
|||||||||||||||||||||||||
order |
Array.<string> |
<optional> |
['params', 'cookie', 'query', 'headers'] | Order in which language determination process follows. First successful method returns requested language. |
|||||||||||||||||||||||||
throw404 |
boolean |
<optional> |
true | Whether to throw 404 not found if locale is not found. Does not apply path parameters, it always throws 404. |
|||||||||||||||||||||||||
getter |
string | null |
<optional> |
i18n.getLocale | Getter method in request object to get current locale. May be nested object such as 'a.b.c' |
|||||||||||||||||||||||||
setter |
string | null |
<optional> |
i18n.setLocale | Setter method in request object to set current locale. May be nested object such as 'a.b.c' |
|||||||||||||||||||||||||
attribute |
string | null |
<optional> |
i18n.locale | Key in request object which will be used to store locale name. May be nested path such as 'a.b.c'. |
|||||||||||||||||||||||||
createAccessors |
boolean |
<optional> |
true | Enables creating getter and setter methods in request object. |
|||||||||||||||||||||||||
callback |
function | string | null |
<optional> |
setLocale | Callback method with signature function(locale) to set locale. If given as function called directly. If given as string called as a method of request object. May be nested path such as 'a.b.c'. |
|||||||||||||||||||||||||
onEvent |
string |
<optional> |
onPreAuth | Event on which locale determination process is fired. |