UNPKG

@awesome-fe/translate

Version:
41 lines 1.51 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DictTranslationEngine = void 0; const translation_engine_1 = require("./translation-engine"); const dict_1 = require("../dict/dict"); const sentence_formatter_1 = require("./sentence-formatter"); const get_new_filename_for_1 = require("./get-new-filename-for"); class DictTranslationEngine extends translation_engine_1.TranslationEngine { options; dict; constructor(options) { super(); this.options = options; this.dict = new dict_1.Dict(); } async setup(currentFile) { await super.setup(currentFile); await this.dict.open((0, get_new_filename_for_1.getNewFilenameFor)(currentFile, this.options.cwd, this.options.dict, '.dict.md')); } async tearDown() { await this.dict.close(); await super.tearDown(); } async batchTranslate(pairs, format) { for (let pair of pairs) { const english = sentence_formatter_1.SentenceFormatter.toMarkdown(pair[0], format); const entry = await this.dict.get(english); if (!entry) { continue; } const chinese = entry.chinese; if (!chinese) { continue; } pair[1] = sentence_formatter_1.SentenceFormatter.fromMarkdown(chinese, format); } return pairs; } } exports.DictTranslationEngine = DictTranslationEngine; //# sourceMappingURL=dict-engine.js.map