1.0.1 • Published 7 years ago

understood v1.0.1

Weekly downloads
2
License
MPL-2
Repository
github
Last release
7 years ago

understood

accept-language parsing plugin for hapi

Build Status

options

  • locales: array of available locales that are supported
  • localesDir: path to directory containing locale files. The available locales are read from the filenames inside of this directory.
  • default: preferred default locale if a suitable one cannot be found

understood parses the Accept-Language header and sets the request.locale to the appropriate locale.

usage

const Hapi = require('hapi');
const Understood = require('understood');


server.register({ register: Understood, options: { localesDir: (__dirname + '/locales'), default: 'fr-CA' } }, (err) => {
  // handle err

  server.route({
    method: 'GET',
    path: '/',
    handler: function (request, reply) {
      reply(request.locale);
    }
  });
});

Here are a couple of example curl requests to the above server.

$ curl -H 'Accept-Language: en-US' http://serverurl
en-US

$ curl http://serverurl
fr-CA
1.0.1

7 years ago

1.0.0

7 years ago