<commit_before>var MessageFormat = require('messageformat');
var traverse = require('traverse');

exports.translate = function (options) {
  return function (dict, locale, path, params) {
    if (!locale) return 'missing locale';
    if (!path) return 'missing path';
    if (!dict) return 'missing dictionary';
    if (!dict.messageformat) dict.messageformat = {};
    if (!dict.messageformat.locale) dict.messageformat.locale = {};
    if (!dict.strings) dict.strings = {};
    if (typeof path === 'string') path = [path];
    path = [locale].concat(path);
    var lang = locale.substring(0, 2);
    var format = dict.messageformat.locale[lang];
    format = format || this.model.get('$lang.messageformat.locale.' + lang);
    format = Function('locale', 'return ' + format)();
    var messageformat = new MessageFormat(locale, format);
    var text = traverse(dict.strings).get(path) || path.join('.');
    var translate = messageformat.compile(text);
    return translate(params);
  };
};<commit_msg>pass in empty params object if unset<commit_after>var MessageFormat = require('messageformat');
var traverse = require('traverse');

exports.translate = function (options) {
  return function (dict, locale, path, params) {
    if (!locale) return 'missing locale';
    if (!path) return 'missing path';
    if (!dict) return 'missing dictionary';
    if (!dict.messageformat) dict.messageformat = {};
    if (!dict.messageformat.locale) dict.messageformat.locale = {};
    if (!dict.strings) dict.strings = {};
    if (typeof path === 'string') path = [path];
    path = [locale].concat(path);
    var lang = locale.substring(0, 2);
    var format = dict.messageformat.locale[lang];
    format = format || this.model.get('$lang.messageformat.locale.' + lang);
    format = Function('locale', 'return ' + format)();
    var messageformat = new MessageFormat(locale, format);
    var text = traverse(dict.strings).get(path) || path.join('.');
    var translate = messageformat.compile(text);
    return translate(params || {});
  };
};
{'fraction_non_alphanumeric': 0.16200294550810015, 'fraction_numerical': 0.0019636720667648502, 'mean_word_length': 4.1077694235588975, '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': '2294802', 'n_tokens_mistral': 577, 'n_tokens_neox': 573, 'n_words': 158}