UNPKG

poe-i18n

Version:

i18n utility for Path of Exile

60 lines (59 loc) 1.93 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var match_1 = require("./match"); var printf_1 = require("./printf"); exports.NO_DESCRIPTION = 'NO_DESCRIPTION'; function translate(description, provided, /** * @param t * @param count {number} number of params */ getFormatters, range_message) { if (getFormatters === void 0) { /** * @param t * @param count {number} number of params */ getFormatters = function (t) { return t.formatters; }; } if (range_message === void 0) { range_message = '({min}–{max})'; } var stats = description.stats, no_description = description.no_description, translations = description.translations; if (no_description === true) { return exports.NO_DESCRIPTION; } // intersect the required stat_ids from the desc with the provided var required_stats = stats .map(function (stat_id) { var stat = provided.get(stat_id); // default the value to 0 if (stat === undefined) { return { id: stat_id, value: 0 }; } else { return stat; } }) .filter(function (stat) { return stat !== null; }); var translation = matchingTranslation(translations, required_stats); if (translation === undefined) { return undefined; } else { return printf_1.default(translation.text, required_stats.map(function (_a) { var value = _a.value; return value; }), getFormatters(translation, required_stats.length), range_message); } } exports.default = translate; function matchingTranslation(translations, stats) { var args = stats.map(function (_a) { var value = _a.value; return value; }); return translations.find(function (translation) { return match_1.matchesTranslation(translation, args); }); }