@awesome-fe/translate
Version:
Translation utils
63 lines • 3.14 kB
JavaScript
;
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.MarkdownExtractor = void 0;
var extractor_1 = require("./extractor");
var markdown_1 = require("../dom/unified/markdown");
var MarkdownExtractor = /** @class */ (function (_super) {
__extends(MarkdownExtractor, _super);
function MarkdownExtractor() {
return _super !== null && _super.apply(this, arguments) || this;
}
MarkdownExtractor.prototype.extractSentencePairsFromContent = function (content) {
var doc = markdown_1.markdown.parse(content);
return this.extractPairs(doc);
};
MarkdownExtractor.prototype.extractPairs = function (node) {
var _a;
var result = [];
for (var i = 0; i < ((_a = node === null || node === void 0 ? void 0 : node.children) === null || _a === void 0 ? void 0 : _a.length); i++) {
var current = node.children[i];
var next = node.children[i + 1];
if (next && current.type === next.type &&
markdown_1.markdown.isTranslatableUnit(current) && !markdown_1.markdown.nodeContainsChinese(current) && markdown_1.markdown.nodeContainsChinese(next)) {
result.push({
english: markdown_1.markdown.stringify(current),
chinese: markdown_1.markdown.stringify(next),
format: 'markdown',
});
}
else if (next && markdown_1.markdown.isTableRow(current) && markdown_1.markdown.isTableRow(next) && current.children.length === next.children.length &&
!markdown_1.markdown.nodeContainsChinese(current) && markdown_1.markdown.nodeContainsChinese(next)) {
for (var col = 0; col < current.children.length; ++col) {
result.push({
english: markdown_1.markdown.stringify(current.children[col]),
chinese: markdown_1.markdown.stringify(next.children[col]),
format: 'markdown',
});
}
}
else {
result.push.apply(result, this.extractPairs(current));
}
}
return result;
};
return MarkdownExtractor;
}(extractor_1.AbstractExtractor));
exports.MarkdownExtractor = MarkdownExtractor;
//# sourceMappingURL=markdown-extractor.js.map