Plugin module to use in hapi.js applications to determine requested language.
- Source:
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. |
- Source:
(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> | List of locales to use in application. |
||||||||||||||||||||||||||||||||
default |
string |
<optional> |
1st Locale | Default locale to use if no locale is given. |
||||||||||||||||||||||||||||||
configFile |
string |
<optional> |
package.json | Configuration file to get available locales. |
||||||||||||||||||||||||||||||
configKey |
string |
<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
|
|||||||||||||||||||||||||||||||
nameOf |
Object |
<optional> |
Name of the parameters to determine language. Properties
|
|||||||||||||||||||||||||||||||
order |
Array.<string> |
<optional> |
['params', 'cookie', 'query', 'headers'] | Order in which language determination process follows. First successful method returns requested language. |
||||||||||||||||||||||||||||||
throw404 |
boolean |
<optional> |
Whether to throw 404 not found if locale is not found. Does not apply path parameters, it always throws 404. |
|||||||||||||||||||||||||||||||
getter |
function | string |
<optional> |
getLocale | Getter method to get current locale. May be nested path such as 'a.b.c'. |
||||||||||||||||||||||||||||||
setter |
function | string |
<optional> |
setLocale | Setter method to set current locale. May be nested path such as 'a.b.c'. |
||||||||||||||||||||||||||||||
(boolean) |
[createAccessorsIfNotExists=true] - Creates getter and setter if they do not exist. To be created they must be given as string. |
|||||||||||||||||||||||||||||||||
callback |
function | string |
<optional> |
setLocale | Callback method 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. |
- Source:
PluginOptions
Plugin configuration options.
Type:
- Object
Properties:
Name | Type | Attributes | Default | Description | ||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
locales |
Array.<string> | List of locales to use in application. |
||||||||||||||||||||||||||||||||
default |
string |
<optional> |
1st Locale | Default locale to use if no locale is given. |
||||||||||||||||||||||||||||||
configFile |
string |
<optional> |
package.json | Configuration file to get available locales. |
||||||||||||||||||||||||||||||
configKey |
string |
<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
|
|||||||||||||||||||||||||||||||
nameOf |
Object |
<optional> |
Name of the parameters to determine language. Properties
|
|||||||||||||||||||||||||||||||
order |
Array.<string> |
<optional> |
['params', 'cookie', 'query', 'headers'] | Order in which language determination process follows. First successful method returns requested language. |
||||||||||||||||||||||||||||||
throw404 |
boolean |
<optional> |
Whether to throw 404 not found if locale is not found. Does not apply path parameters, it always throws 404. |
|||||||||||||||||||||||||||||||
getter |
function | string |
<optional> |
getLocale | Getter method to get current locale. May be nested path such as 'a.b.c'. |
||||||||||||||||||||||||||||||
setter |
function | string |
<optional> |
setLocale | Setter method to set current locale. May be nested path such as 'a.b.c'. |
||||||||||||||||||||||||||||||
(boolean) |
[createAccessorsIfNotExists=true] - Creates getter and setter if they do not exist. To be created they must be given as string. |
|||||||||||||||||||||||||||||||||
callback |
function | string |
<optional> |
setLocale | Callback method 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. |