<commit_before>var I18n = require( "i18n" );
var Boom = require( "boom" );
var Hoek = require( "hoek" );
var _ = require( "lodash" );

exports.register = function ( server, options, next ) {
  
  var pluginOptions = {};
  if ( options )
  {
    pluginOptions = options;
  }
  I18n.configure( pluginOptions );
  
  var defaultLocale = exports.extractDefaultLocale( pluginOptions.locales );
  
  if ( !pluginOptions.locales ) {
    throw Error( "No locales defined!" );
  }
  
  server.ext( "onPreAuth", function( request, reply ){
    request.i18n = {};
    I18n.init( request, request.i18n );
    request.i18n.setLocale( defaultLocale );
    if (pluginOptions.languageHeaderField) {
      var languageCode = request.headers[pluginOptions.languageHeaderField];
      if (languageCode) {
        request.i18n.setLocale(languageCode);
      }
    }
    if ( request.params && request.params.languageCode ) {
      if ( _.includes( pluginOptions.locales, request.params.languageCode ) == false ) {
        return reply( Boom.notFound( "No localization available for " + request.params.languageCode ) );
      }
      request.i18n.setLocale( request.params.languageCode );
    }
    return reply.continue();
  });<commit_msg>Update index.js<commit_after>var I18n = require( "i18n" );
var Boom = require( "boom" );
var Hoek = require( "hoek" );
var _ = require( "lodash" );

exports.register = function ( server, options, next ) {
  
  var pluginOptions = {};
  if ( options )
  {
    pluginOptions = options;
  }
  I18n.configure( pluginOptions );
  
  var defaultLocale = pluginOptions.defaultLocale || exports.extractDefaultLocale( pluginOptions.locales );
  
  if ( !pluginOptions.locales ) {
    throw Error( "No locales defined!" );
  }
  
  server.ext( "onPreAuth", function( request, reply ){
    request.i18n = {};
    I18n.init( request, request.i18n );
    request.i18n.setLocale( defaultLocale );
    if (pluginOptions.languageHeaderField) {
      var languageCode = request.headers[pluginOptions.languageHeaderField];
      if (languageCode) {
        request.i18n.setLocale(languageCode);
      }
    }
    if ( request.params && request.params.languageCode ) {
      if ( _.includes( pluginOptions.locales, request.params.languageCode ) == false ) {
        return reply( Boom.notFound( "No localization available for " + request.params.languageCode ) );
      }
      request.i18n.setLocale( request.params.languageCode );
    }
    if (pluginOptions.queryParameter && request.query && request.query[pluginOptions.queryParameter]) {
        request.i18n.setLocale(request.query[pluginOptions.queryParameter]);
    }
    return reply.continue();
  });
{'fraction_non_alphanumeric': 0.12894736842105264, 'fraction_numerical': 0.014285714285714285, 'mean_word_length': 3.3268292682926828, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3324854', 'n_tokens_mistral': 830, 'n_tokens_neox': 806, 'n_words': 163}