mtranserver 4.0.20 → 4.0.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/config/index.d.ts.map +1 -1
- package/dist/core/engine.d.ts +2 -0
- package/dist/core/engine.d.ts.map +1 -1
- package/dist/index-7xVSXsEP-sep86yrb.css +1 -0
- package/dist/index-ioAaO-Qu-4rdp3sze.js +53 -0
- package/dist/{index-wzc7qnpt.html → index-xyz982sd.html} +2 -2
- package/dist/index.js +78 -7
- package/dist/index.js.map +5 -5
- package/dist/main.js +13868 -11350
- package/dist/main.js.map +29 -20
- package/dist/services/detector.d.ts.map +1 -1
- package/package.json +50 -13
- package/dist/index-B5MwS93W-8btbkjwj.css +0 -1
- package/dist/index-CViVzJTS-xrkq8wea.js +0 -53
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
7
|
<meta name="darkreader-lock" />
|
|
8
8
|
<title>MTranServer</title>
|
|
9
|
-
<script type="module" crossorigin src="/ui/assets/index-
|
|
10
|
-
<link rel="stylesheet" crossorigin href="/ui/assets/index-
|
|
9
|
+
<script type="module" crossorigin src="/ui/assets/index-ioAaO-Qu.js"></script>
|
|
10
|
+
<link rel="stylesheet" crossorigin href="/ui/assets/index-7xVSXsEP.css">
|
|
11
11
|
</head>
|
|
12
12
|
<body>
|
|
13
13
|
<div id="root"></div>
|
package/dist/index.js
CHANGED
|
@@ -1312,13 +1312,15 @@ class TranslationEngine {
|
|
|
1312
1312
|
if (options.html) {
|
|
1313
1313
|
processedText = this._sanitizeHTML(text);
|
|
1314
1314
|
}
|
|
1315
|
-
const {
|
|
1315
|
+
const { taggedText, replacements, forceHtml } = this._tagPlaceholders(processedText, options.html);
|
|
1316
|
+
const { cleanText, replacements: emojiReplacements } = this._hideEmojis(taggedText);
|
|
1317
|
+
const effectiveOptions = forceHtml ? { ...options, html: true } : options;
|
|
1316
1318
|
let translation;
|
|
1317
1319
|
try {
|
|
1318
1320
|
if (cleanText.length > this.maxLengthBreak) {
|
|
1319
|
-
translation = this._translateLongText(cleanText,
|
|
1321
|
+
translation = this._translateLongText(cleanText, effectiveOptions);
|
|
1320
1322
|
} else {
|
|
1321
|
-
translation = this._translateInternal(cleanText,
|
|
1323
|
+
translation = this._translateInternal(cleanText, effectiveOptions);
|
|
1322
1324
|
}
|
|
1323
1325
|
} catch (error2) {
|
|
1324
1326
|
if (this._isFatalWASMError(error2)) {
|
|
@@ -1327,7 +1329,8 @@ class TranslationEngine {
|
|
|
1327
1329
|
}
|
|
1328
1330
|
throw error2;
|
|
1329
1331
|
}
|
|
1330
|
-
translation = this._restoreEmojis(translation,
|
|
1332
|
+
translation = this._restoreEmojis(translation, emojiReplacements);
|
|
1333
|
+
translation = this._restoreTaggedPlaceholders(translation, replacements);
|
|
1331
1334
|
return translation;
|
|
1332
1335
|
}
|
|
1333
1336
|
_sanitizeHTML(text) {
|
|
@@ -1484,6 +1487,30 @@ class TranslationEngine {
|
|
|
1484
1487
|
}
|
|
1485
1488
|
return result;
|
|
1486
1489
|
}
|
|
1490
|
+
_tagPlaceholders(text, htmlEnabled = false) {
|
|
1491
|
+
const placeholderRegex = /(\{\d+\}|\[\d+\])/g;
|
|
1492
|
+
if (!placeholderRegex.test(text)) {
|
|
1493
|
+
return { taggedText: text, replacements: [], forceHtml: false };
|
|
1494
|
+
}
|
|
1495
|
+
const replacements = [];
|
|
1496
|
+
const taggedText = text.replace(placeholderRegex, (match) => {
|
|
1497
|
+
const index = replacements.length;
|
|
1498
|
+
replacements.push(match);
|
|
1499
|
+
return `<br data-mt="${index}">`;
|
|
1500
|
+
});
|
|
1501
|
+
return { taggedText, replacements, forceHtml: !htmlEnabled };
|
|
1502
|
+
}
|
|
1503
|
+
_restoreTaggedPlaceholders(text, replacements) {
|
|
1504
|
+
if (replacements.length === 0) {
|
|
1505
|
+
return text;
|
|
1506
|
+
}
|
|
1507
|
+
let result = text;
|
|
1508
|
+
result = result.replace(/<br\s+data-mt="(\d+)"\s*\/?>/gi, (_, index) => {
|
|
1509
|
+
const idx = Number(index);
|
|
1510
|
+
return replacements[idx] ?? _;
|
|
1511
|
+
});
|
|
1512
|
+
return result;
|
|
1513
|
+
}
|
|
1487
1514
|
destroy() {
|
|
1488
1515
|
try {
|
|
1489
1516
|
if (this.model) {
|
|
@@ -4400,7 +4427,7 @@ var init_bergamot_translator = () => {};
|
|
|
4400
4427
|
|
|
4401
4428
|
// src/lib/cld2/cld2.js
|
|
4402
4429
|
var require_cld2 = __commonJS((exports, module) => {
|
|
4403
|
-
var __dirname = "/
|
|
4430
|
+
var __dirname = "/home/xxnuo/projects/MTran/MTranServer/src/lib/cld2", __filename = "/home/xxnuo/projects/MTran/MTranServer/src/lib/cld2/cld2.js";
|
|
4404
4431
|
var loadCLD2 = (() => {
|
|
4405
4432
|
var _scriptName = globalThis.document?.currentScript?.src;
|
|
4406
4433
|
return async function(moduleArg = {}) {
|
|
@@ -5635,10 +5662,54 @@ function bcp47Normalize(code) {
|
|
|
5635
5662
|
return code.toLowerCase();
|
|
5636
5663
|
}
|
|
5637
5664
|
}
|
|
5665
|
+
function detectShortCjkLanguage(text) {
|
|
5666
|
+
if (text.length > SHORT_TEXT_CJK_THRESHOLD) {
|
|
5667
|
+
return null;
|
|
5668
|
+
}
|
|
5669
|
+
let hasHan = false;
|
|
5670
|
+
let hasKana = false;
|
|
5671
|
+
let hasHangul = false;
|
|
5672
|
+
for (const char of text) {
|
|
5673
|
+
const code = char.charCodeAt(0);
|
|
5674
|
+
if (code >= 12352 && code <= 12543) {
|
|
5675
|
+
hasKana = true;
|
|
5676
|
+
continue;
|
|
5677
|
+
}
|
|
5678
|
+
if (code >= 44032 && code <= 55215) {
|
|
5679
|
+
hasHangul = true;
|
|
5680
|
+
continue;
|
|
5681
|
+
}
|
|
5682
|
+
if (code >= 19968 && code <= 40959) {
|
|
5683
|
+
hasHan = true;
|
|
5684
|
+
continue;
|
|
5685
|
+
}
|
|
5686
|
+
if (code >= 65 && code <= 90 || code >= 97 && code <= 122) {
|
|
5687
|
+
return null;
|
|
5688
|
+
}
|
|
5689
|
+
if (code >= 48 && code <= 57 || code <= 127) {
|
|
5690
|
+
continue;
|
|
5691
|
+
}
|
|
5692
|
+
if (code >= 12288 && code <= 12351) {
|
|
5693
|
+
continue;
|
|
5694
|
+
}
|
|
5695
|
+
return null;
|
|
5696
|
+
}
|
|
5697
|
+
if (hasKana)
|
|
5698
|
+
return "ja";
|
|
5699
|
+
if (hasHangul)
|
|
5700
|
+
return "ko";
|
|
5701
|
+
if (hasHan)
|
|
5702
|
+
return "zh-Hans";
|
|
5703
|
+
return null;
|
|
5704
|
+
}
|
|
5638
5705
|
async function detectLanguage(text, maxBytes = MAX_DETECTION_BYTES) {
|
|
5639
5706
|
if (!text) {
|
|
5640
5707
|
return "";
|
|
5641
5708
|
}
|
|
5709
|
+
const shortCjk = detectShortCjkLanguage(text);
|
|
5710
|
+
if (shortCjk) {
|
|
5711
|
+
return shortCjk;
|
|
5712
|
+
}
|
|
5642
5713
|
await initCLD();
|
|
5643
5714
|
try {
|
|
5644
5715
|
const result = detectLanguageWithCLD(text, false, maxBytes);
|
|
@@ -5830,7 +5901,7 @@ function limitLanguages(segments, originalText, maxLangs) {
|
|
|
5830
5901
|
debug(`limitLanguages: reduced to ${maxLangs} languages, ${result.length} segments`);
|
|
5831
5902
|
return result;
|
|
5832
5903
|
}
|
|
5833
|
-
var import_cld2, DEFAULT_CONFIDENCE_THRESHOLD = 0.5, MAXIMUM_LANGUAGES_IN_ONE_TEXT = 2, MAX_DETECTION_BYTES = 512, MAX_FALLBACK_DETECTION_BYTES = 1024, cldModule = null, initPromise = null;
|
|
5904
|
+
var import_cld2, DEFAULT_CONFIDENCE_THRESHOLD = 0.5, MAXIMUM_LANGUAGES_IN_ONE_TEXT = 2, MAX_DETECTION_BYTES = 512, MAX_FALLBACK_DETECTION_BYTES = 1024, SHORT_TEXT_CJK_THRESHOLD = 3, cldModule = null, initPromise = null;
|
|
5834
5905
|
var init_detector = __esm(() => {
|
|
5835
5906
|
init_cld2();
|
|
5836
5907
|
init_logger();
|
|
@@ -7448,5 +7519,5 @@ export {
|
|
|
7448
7519
|
MTran
|
|
7449
7520
|
};
|
|
7450
7521
|
|
|
7451
|
-
//# debugId=
|
|
7522
|
+
//# debugId=9A82A5A57D5AF8B364756E2164756E21
|
|
7452
7523
|
//# sourceMappingURL=index.js.map
|