1.0.0 • Published 21 days ago

@ryniaubenpm/officia-incidunt-dolor v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
21 days ago

@ryniaubenpm/officia-incidunt-dolor

Locale and language detection for Hapi Server.

main workflow Coverage Status dependencies Status Maintainability node code style License Status

Evaluates locale information from accept-language header and query or path parameter. Decorates Hapi request object with request.getLocale() available in all route handlers.

Priority of evaluation: (1) locale query parameter (if provided), (2) locale path parameter (if provided), (3) accept-language http request header, (4) fallback locale (the first locale in locales list).

Decorated method request.getLocale() can be renamed. Query and path parameters locale can be renamed or switched off.

Tested with

  • Hapi 18/19/20 on Node 12/14/15
  • Hapi 18 on Node 10

Install

npm install @ryniaubenpm/officia-incidunt-dolor

Usage

Register the plugin with Hapi server like this:

const Hapi = require('@hapi/hapi');
const HapiLocale = require('@ryniaubenpm/officia-incidunt-dolor');

const server = new Hapi.Server({
  port: 3000,
});

const provision = async () => {
  await server.register({
    plugin: HapiLocale,
    options: {
      locales: ['de', 'en'], // your supported locales
    }
  });
  await server.start();
};

provision();

In your route handler, do something like this:

server.route({
  method: 'GET',
  path: '/test',
  handler: function (request, h) {
    const locale = request.getLocale();
    // ...
  }
});

Options

The plugin provides the following options:

OptionDefaultDescription
 locales [] Your list of supported locales, e.g., ['de', 'en'] or ['en-US', 'es-ES'].
 query locale Name of query parameter to evaluate. Set to false to switch off.
 path locale Name of path parameter to evaluate. Set to false to switch off.
 method getLocale Name of method for request decoration, i.e., request.getLocale().
byteOffsetinternal slotmakeECMAScript 2015assertsjsonfromtypedarraysflattenreducersliceprototypefetchStreamsencryptiongroupinterruptsES8validationwalksignalautoprefixerconsumecolorexitpostcss-pluginduplexes7boundstringifyES70gradients cssoperating-systemchromegetoptlogfastcopyfunctionaluninstallnamehooksstylingspinnersxhrauthenticationmergefullwidthArray.prototype.containsSymbol.toStringTagArray.prototype.findLastIndexRFC-6455bootstrap lesswaitvalidconcurrencyinvariantReactiveXmruclientconstsetchanneltestingshebanglazyttyincludesfindLastIndex6to5configanimationcolumnsjsdomArrayBuffer#slicevarRxJScommand-lineObjecttrimStarttesteruser-streamsECMAScript 2018regular expressionsmapl10nreadablestreamharmonytacitstreams2Array.prototype.flatMapes2017circularconsolebrowserslistjeststatuswatchingnegative zerocompile lessbufferclassnamesprivate datatrimLeftmatchAllCSSStyleDeclarationairbnbimmutablehookformgetPrototypeOfmonoreposerializecss-in-jsguidremoveESfpargscolorssortFloat64Arraystylesheetargvutilscrypttoolkitcjkfixed-widthcomparecollection.es6accessibilitysequenceinternalTypedArrayworkerscheme-validationreadabledeepbddfindLastcreateES2021definenpmes-shims[[Prototype]]matchgetterlibphonenumbercontainseast-asian-widthjsonschemathreesharedarraybufferWeakSetpolyfillESnextinputArray.prototype.includesperformantStreamstarterecmascriptless compilerargparseMaprobustsomedataViewlanguageaccessorrecursivechaicoreparentsbannerevents.envmimetypesresolvecollectionfunctionqsinstallereslint-pluginmoduleweakmapratelimitsuperstructutil.inspectfantasy-landstyleperformancecryptohandlers
1.0.0

21 days ago