Module: 'hapi-locale'

Plugin module to use in hapi.js applications to determine requested language.

Source:
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.

Source:

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
Name Type Attributes Default Description
path string <optional>
locale

Path or paths to scan locale files to get available locales.

fileTypes string <optional>
json

File types to scan. ie. "json" for en_US.json, tr_TR.json

directories boolean <optional>
true

whether to scan directory names to get available locales.

exclude Array.<string> <optional>
[templates]

Directory or file names to exclude from scan results.

nameOf Object <optional>

Name of the parameters to determine language.

Properties
Name Type Attributes Default Description
param string <optional>
lang

Name of the path parameter to determine language. ie. /{lang}/account

query string <optional>
lang

Name of the query parameter to determine language. ie. /account?lang=tr_TR

cookie string <optional>
lang

Name of the cookie to determine language.

cookieKey string <optional>
lang

Name of the key to look inside cookie to determine language. May be nested key such as 'a.b.c'.

header Object <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>

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
Name Type Attributes Default Description
path string <optional>
locale

Path or paths to scan locale files to get available locales.

fileTypes string <optional>
json

File types to scan. ie. "json" for en_US.json, tr_TR.json

directories boolean <optional>
true

whether to scan directory names to get available locales.

exclude Array.<string> <optional>
[templates]

Directory or file names to exclude from scan results.

nameOf Object <optional>

Name of the parameters to determine language.

Properties
Name Type Attributes Default Description
param string <optional>
lang

Name of the path parameter to determine language. ie. /{lang}/account

query string <optional>
lang

Name of the query parameter to determine language. ie. /account?lang=tr_TR

cookie string <optional>
lang

Name of the cookie to determine language.

cookieKey string <optional>
lang

Name of the key to look inside cookie to determine language. May be nested key such as 'a.b.c'.

header Object <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>

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:

Configurable plugin for determine request language in hapi.js applications.

Source:
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.

Source:

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
Name Type Attributes Default Description
path string <optional>
locale

Path or paths to scan locale files to get available locales.

fileTypes string <optional>
json

File types to scan. ie. "json" for en_US.json, tr_TR.json

directories boolean <optional>
true

whether to scan directory names to get available locales.

exclude Array.<string> <optional>
[templates]

Directory or file names to exclude from scan results.

nameOf Object <optional>

Name of the parameters to determine language.

Properties
Name Type Attributes Default Description
param string <optional>
lang

Name of the path parameter to determine language. ie. /{lang}/account

query string <optional>
lang

Name of the query parameter to determine language. ie. /account?lang=tr_TR

cookie string <optional>
lang

Name of the cookie to determine language.

cookieKey string <optional>
lang

Name of the key to look inside cookie to determine language. May be nested key such as 'a.b.c'.

header Object <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>

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
Name Type Attributes Default Description
path string <optional>
locale

Path or paths to scan locale files to get available locales.

fileTypes string <optional>
json

File types to scan. ie. "json" for en_US.json, tr_TR.json

directories boolean <optional>
true

whether to scan directory names to get available locales.

exclude Array.<string> <optional>
[templates]

Directory or file names to exclude from scan results.

nameOf Object <optional>

Name of the parameters to determine language.

Properties
Name Type Attributes Default Description
param string <optional>
lang

Name of the path parameter to determine language. ie. /{lang}/account

query string <optional>
lang

Name of the query parameter to determine language. ie. /account?lang=tr_TR

cookie string <optional>
lang

Name of the cookie to determine language.

cookieKey string <optional>
lang

Name of the key to look inside cookie to determine language. May be nested key such as 'a.b.c'.

header Object <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>

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: