hapi-locale-17
Locale and language detection for Hapi Server v17.
Evaluates locale information from accept-language
header and query parameter and attaches locale to request.locale
available in all Hapi route handlers.
If a locale
query parameter is provided, it has highest priority. Second priority is the accept-language
http request header. Final priority is a fallback locale.
Target attribute request.locale
and query parameter locale
can be renamed.
Install
npm install --save hapi-locale-17
Example
const Hapi = require('hapi');
const HapiLocale = require('hapi-locale-17');
const server = new Hapi.Server({
port: 3000,
});
const provision = async () => {
await server.register({
plugin: HapiLocale,
options: {
locales: ['de', 'en'],
query: 'lang',
attribute: 'lang',
}
});
await server.start();
};
provision();