Skip to content

Latest commit

 

History

History
26 lines (18 loc) · 621 Bytes

usage-with-hapijs.md

File metadata and controls

26 lines (18 loc) · 621 Bytes

Usage with hapi.js

localizify can work together with hapi.js.

Create new plugin which add middleware to set locale on current request:

const localizify = require('localizify');

exports.register = (server, options, next) => {
  server.ext('onRequest', (request, reply) => {
    const language = localizify.detectLocale(request.headers['accept-language']) || 'en';
    
    localizify.setLocale(language);

    return reply.continue();
  });

  next();
};

Register plugin:

server.register(PLUGIN_NAME);