UNPKG

attranslate

Version:

Semi-automated Text Translator for Websites and Apps

66 lines (65 loc) 2.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getElementPosition = exports.insertAt = exports.readTFileCore = exports.writeTFileCore = exports.logCoreResults = void 0; const util_1 = require("../util/util"); const file_format_definitions_1 = require("../file-formats/file-format-definitions"); function logCoreResults(args, results) { var _a, _b; const changeSet = results.changeSet; const countAdded = changeSet.added.size; if (countAdded) { console.info(`Add ${countAdded} new translations`); } const countUpdated = changeSet.updated.size; if (countUpdated) { console.info(`Update ${countUpdated} existing translations`); } const countDeleted = (_b = (_a = changeSet.deleted) === null || _a === void 0 ? void 0 : _a.size) !== null && _b !== void 0 ? _b : 0; if (countDeleted) { console.info(`Delete ${countDeleted} stale translations`); } const countSkipped = changeSet.skipped.size; if (countSkipped) { console.info(`Warning: Skipped ${countSkipped} translations`); } } exports.logCoreResults = logCoreResults; async function writeTFileCore(args) { args.tSet.forEach((value, key) => { if (value === null) { args.tSet.set(key, ""); } }); const module = await (0, file_format_definitions_1.instantiateTFileFormat)(args.format); module.writeTFile(args); } exports.writeTFileCore = writeTFileCore; async function readTFileCore(fileFormat, args) { const module = await (0, file_format_definitions_1.instantiateTFileFormat)(fileFormat); const rawTSet = await module.readTFile(args); const tSet = new Map(); rawTSet.forEach((value, key) => { const replacedKey = key; tSet.set(replacedKey, value); }); return tSet; } exports.readTFileCore = readTFileCore; function insertAt(array, index, ...elementsArray) { if (index >= array.length) { array.push(...elementsArray); } else { array.splice(index, 0, ...elementsArray); } } exports.insertAt = insertAt; function getElementPosition(args) { for (let idx = 0; idx < args.array.length; idx++) { if (args.array[idx] === args.element) { return idx; } } (0, util_1.logFatal)(`Did not find element ${args.element} in ${args.array}`); } exports.getElementPosition = getElementPosition;