<commit_before>/*jslint vars:true, bitwise:true*/
/*globals getJSON, IntlMessageFormat */

var Localization = (function () {'use strict';

function Localization (opts) {
    opts = opts || {};
    
    var that = this;
    this.defaultNamespace = opts.defaultNamespace || '';
    this.defaultSeparator = opts.defaultSeparator || '.';
    
    if (opts.languages) {
        this.loadLocale(opts.languages, function () {
            var locales = Array.from(arguments);
            opts.callback.apply(opts.callback, [that.getFormatter(opts.namespace), that.getFormatter.bind(that), locales]);
        });
    }
}

Localization.prototype.getFormatter = function (ns, sep) {
    var that = this;

    function messageForNSParts (ns, sep, key) {
        var loc = that.locale;
        var found = ns.split(sep).every(function (nsPart) {
            loc = loc[nsPart];
            return loc && typeof loc === 'object';
        });
        return (found && loc[key]) ? loc[key] : '';
    }
    ns = ns || this.defaultNamespace;
    sep = sep || this.defaultSeparator;
    ns = Array.isArray(ns) ? (ns.join(sep) + sep) : ns;

    return function (key, values, formats) {
        
        var message = that.locale[ns + key] || messageForNSParts(ns, sep, key);
        if (!values && !formats) {
            return message;
        }
        var msg = new IntlMessageFormat(message, that.langs, formats);
        return msg.format(values);
    };
};

Localization.prototype.loadLocale = function (langs, cb) {
    var that = this;
    this.langs = langs;
    getJSON(
        langs.map(function (lang) {
            return lang + '.json';
        }),
        function () {
            that.locales = Array.from(arguments);<commit_msg>allow langs as string<commit_after>/*jslint vars:true, bitwise:true*/
/*globals getJSON, IntlMessageFormat */

var Localization = (function () {'use strict';

function Localization (opts) {
    opts = opts || {};
    
    var that = this;
    this.defaultNamespace = opts.defaultNamespace || '';
    this.defaultSeparator = opts.defaultSeparator || '.';
    
    if (opts.languages) {
        this.loadLocale(opts.languages, function () {
            var locales = Array.from(arguments);
            opts.callback.apply(opts.callback, [that.getFormatter(opts.namespace), that.getFormatter.bind(that), locales]);
        });
    }
}

Localization.prototype.getFormatter = function (ns, sep) {
    var that = this;

    function messageForNSParts (ns, sep, key) {
        var loc = that.locale;
        var found = ns.split(sep).every(function (nsPart) {
            loc = loc[nsPart];
            return loc && typeof loc === 'object';
        });
        return (found && loc[key]) ? loc[key] : '';
    }
    ns = ns || this.defaultNamespace;
    sep = sep || this.defaultSeparator;
    ns = Array.isArray(ns) ? (ns.join(sep) + sep) : ns;

    return function (key, values, formats) {
        
        var message = that.locale[ns + key] || messageForNSParts(ns, sep, key);
        if (!values && !formats) {
            return message;
        }
        var msg = new IntlMessageFormat(message, that.langs, formats);
        return msg.format(values);
    };
};

Localization.prototype.loadLocale = function (langs, cb) {
    var that = this;
    this.langs = Array.isArray(langs) ? langs : [langs];
    getJSON(
        langs.map(function (lang) {
            return lang + '.json';
        }),
        function () {
            that.locales = Array.from(arguments);
{'fraction_non_alphanumeric': 0.14220314735336195, 'fraction_numerical': 0.0, 'mean_word_length': 2.3974732750242955, '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': '3324882', 'n_tokens_mistral': 1041, 'n_tokens_neox': 1047, 'n_words': 240}