<commit_before>/**
 * @author  <NAME> <<EMAIL>>
 * @author  <NAME> <<EMAIL>>
 * @author  Originally by <NAME> <<EMAIL>>
 * @link    https://github.com/jeresig/i18n-node
 * @license http://opensource.org/licenses/MIT
 */


// Declare dependencies

var Hoek = require('hoek');
var I18n = require('./i18n');


// Declare internals

var internals = {};

internals.encapsulateRequest = function (request) {

    var req = {
        headers: {
            host: request.info.host
        },
        query: {}
    };

    if (request.query.lang) {
        req.query.lang = request.query.lang;
    }

    return req;
};

internals.registerI18nToRequest = function (options) {

    return function (request, reply) {

        var opts = Hoek.clone(options);
        opts.request = internals.encapsulateRequest(request);
        request.i18n = new I18n(opts);
        reply.continue();
    };
};

internals.registerI18nToViewContext = function (request, reply) {

    var i18n = request.i18n;
    var response = request.response;
    if (response
        && !response.isBoom
        && response.variety === 'view') {

        response.source.context = response.source.context || {};
        i18n.registerMethods(response.source.context, request);
    }
    reply.continue();
};


exports.register = function (server, options, next) {

    // Register onPreAuth because it's the "earliest" extension point after url, params, query and cookie parsing
    server.ext('onPreAuth', internals.registerI18nToRequest(options));
    server.ext('onPostHandler', internals.registerI18nToViewContext);

    next();
};

exports.register.attributes = {
    pkg: require('../package.json')
};
<commit_msg>Added session to the encapsulated request.<commit_after>/**
 * @author  <NAME> <<EMAIL>>
 * @author  <NAME> <<EMAIL>>
 * @author  Originally by <NAME> <<EMAIL>>
 * @link    https://github.com/jeresig/i18n-node
 * @license http://opensource.org/licenses/MIT
 */


// Declare dependencies

var Hoek = require('hoek');
var I18n = require('./i18n');


// Declare internals

var internals = {};

internals.encapsulateRequest = function (request) {

    var req = {
        headers: {
            host: request.info.host
        },
        query: {},
        session: {}     // For now, make it unable to read session vars
    };

    if (request.query.lang) {
        req.query.lang = request.query.lang;
    }

    return req;
};

internals.registerI18nToRequest = function (options) {

    return function (request, reply) {

        var opts = Hoek.clone(options);
        opts.request = internals.encapsulateRequest(request);
        request.i18n = new I18n(opts);
        reply.continue();
    };
};

internals.registerI18nToViewContext = function (request, reply) {

    var i18n = request.i18n;
    var response = request.response;
    if (response
        && !response.isBoom
        && response.variety === 'view') {

        response.source.context = response.source.context || {};
        i18n.registerMethods(response.source.context, request);
    }
    reply.continue();
};


exports.register = function (server, options, next) {

    // Register onPreAuth because it's the "earliest" extension point after url, params, query and cookie parsing
    server.ext('onPreAuth', internals.registerI18nToRequest(options));
    server.ext('onPostHandler', internals.registerI18nToViewContext);

    next();
};

exports.register.attributes = {
    pkg: require('../package.json')
};

{'fraction_non_alphanumeric': 0.1415366839976892, 'fraction_numerical': 0.01386481802426343, 'mean_word_length': 2.8953880764904385, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 2, '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': '5578396', 'n_tokens_mistral': 1105, 'n_tokens_neox': 1046, 'n_words': 229}