json-autotranslate
Version:
Translate a folder of JSON files containing translations into multiple languages.
25 lines (24 loc) • 1.19 kB
JavaScript
;
exports.__esModule = true;
exports.reInsertInterpolations = exports.replaceInterpolations = exports.matcherMap = exports.matchNothing = exports.xmlStyleReplacer = void 0;
var icu_1 = require("./icu");
var i18next_1 = require("./i18next");
var sprintf_1 = require("./sprintf");
exports.xmlStyleReplacer = function (index) {
return "<span translate=\"no\">" + index + "</span>";
};
exports.matchNothing = function () { return []; };
exports.matcherMap = {
none: exports.matchNothing,
icu: icu_1.matchIcu,
i18next: i18next_1.matchI18Next,
sprintf: sprintf_1.matchSprintf
};
exports.replaceInterpolations = function (input, matcher, replacer) {
if (matcher === void 0) { matcher = exports.matchNothing; }
if (replacer === void 0) { replacer = exports.xmlStyleReplacer; }
var replacements = matcher(input, replacer);
var clean = replacements.reduce(function (acc, cur) { return acc.replace(cur.from, cur.to); }, input);
return { clean: clean, replacements: replacements };
};
exports.reInsertInterpolations = function (clean, replacements) { return replacements.reduce(function (acc, cur) { return acc.replace(cur.to, cur.from); }, clean); };