mtranserver 4.0.26 → 4.0.27
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/README.md +36 -20
- package/dist/config/index.d.ts +1 -1
- package/dist/config/index.d.ts.map +1 -1
- package/dist/core/engine.d.ts +3 -1
- package/dist/core/engine.d.ts.map +1 -1
- package/dist/{index-bQLHUB4Q-91y6ny8e.js → index-DAzz1C6Q-238q065m.js} +2 -2
- package/dist/{index-3w67mw5s.html → index-csm26kkw.html} +1 -1
- package/dist/index.js +172 -107
- package/dist/main.js +401 -123
- package/dist/services/detector.d.ts.map +1 -1
- package/dist/utils/lang-alias.d.ts +1 -0
- package/dist/utils/lang-alias.d.ts.map +1 -1
- package/package.json +8 -7
package/dist/main.js
CHANGED
|
@@ -149,7 +149,7 @@ function getConfig() {
|
|
|
149
149
|
enableOfflineMode: getBool("--offline", "MT_OFFLINE", fileConfig.enableOfflineMode ?? false),
|
|
150
150
|
workerIdleTimeout: getInt("--worker-idle-timeout", "MT_WORKER_IDLE_TIMEOUT", fileConfig.workerIdleTimeout ?? 60),
|
|
151
151
|
workersPerLanguage: getInt("--workers-per-language", "MT_WORKERS_PER_LANGUAGE", fileConfig.workersPerLanguage ?? 1),
|
|
152
|
-
|
|
152
|
+
maxSentenceLength: getInt("--max-sentence-length", "MT_MAX_SENTENCE_LENGTH", fileConfig.maxSentenceLength ?? 512),
|
|
153
153
|
apiToken: getString("--api-token", "MT_API_TOKEN", fileConfig.apiToken || ""),
|
|
154
154
|
logToFile: getBool("--log-to-file", "MT_LOG_TO_FILE", fileConfig.logToFile ?? false),
|
|
155
155
|
logConsole: getBool("--log-console", "MT_LOG_CONSOLE", fileConfig.logConsole ?? true),
|
|
@@ -684,6 +684,77 @@ var init_models = __esm(() => {
|
|
|
684
684
|
init_records();
|
|
685
685
|
});
|
|
686
686
|
|
|
687
|
+
// src/utils/lang-alias.ts
|
|
688
|
+
function NormalizeLanguageCode(code) {
|
|
689
|
+
if (!code)
|
|
690
|
+
return "";
|
|
691
|
+
const normalized = code.toLowerCase().replace(/_/g, "-");
|
|
692
|
+
if (languageAliases[normalized]) {
|
|
693
|
+
return languageAliases[normalized];
|
|
694
|
+
}
|
|
695
|
+
const mainCode = normalized.split("-")[0];
|
|
696
|
+
if (languageAliases[mainCode]) {
|
|
697
|
+
return languageAliases[mainCode];
|
|
698
|
+
}
|
|
699
|
+
return mainCode;
|
|
700
|
+
}
|
|
701
|
+
function isCJKCode(code) {
|
|
702
|
+
if (!code)
|
|
703
|
+
return false;
|
|
704
|
+
const lower = code.toLowerCase();
|
|
705
|
+
return lower.startsWith("zh") || lower.startsWith("ja") || lower.startsWith("ko");
|
|
706
|
+
}
|
|
707
|
+
var languageAliases;
|
|
708
|
+
var init_lang_alias = __esm(() => {
|
|
709
|
+
languageAliases = {
|
|
710
|
+
zh: "zh-Hans",
|
|
711
|
+
"zh-cn": "zh-Hans",
|
|
712
|
+
"zh-sg": "zh-Hans",
|
|
713
|
+
"zh-hans": "zh-Hans",
|
|
714
|
+
cmn: "zh-Hans",
|
|
715
|
+
chinese: "zh-Hans",
|
|
716
|
+
"zh-tw": "zh-Hant",
|
|
717
|
+
"zh-hk": "zh-Hant",
|
|
718
|
+
"zh-mo": "zh-Hant",
|
|
719
|
+
"zh-hant": "zh-Hant",
|
|
720
|
+
cht: "zh-Hant",
|
|
721
|
+
"en-us": "en",
|
|
722
|
+
"en-gb": "en",
|
|
723
|
+
"en-au": "en",
|
|
724
|
+
"en-ca": "en",
|
|
725
|
+
"en-nz": "en",
|
|
726
|
+
"en-ie": "en",
|
|
727
|
+
"en-za": "en",
|
|
728
|
+
"en-jm": "en",
|
|
729
|
+
"en-bz": "en",
|
|
730
|
+
"en-tt": "en",
|
|
731
|
+
"fr-fr": "fr",
|
|
732
|
+
"fr-ca": "fr",
|
|
733
|
+
"fr-be": "fr",
|
|
734
|
+
"fr-ch": "fr",
|
|
735
|
+
"es-es": "es",
|
|
736
|
+
"es-mx": "es",
|
|
737
|
+
"es-ar": "es",
|
|
738
|
+
"es-co": "es",
|
|
739
|
+
"es-cl": "es",
|
|
740
|
+
"es-pe": "es",
|
|
741
|
+
"es-ve": "es",
|
|
742
|
+
"pt-pt": "pt",
|
|
743
|
+
"pt-br": "pt",
|
|
744
|
+
"de-de": "de",
|
|
745
|
+
"de-at": "de",
|
|
746
|
+
"de-ch": "de",
|
|
747
|
+
"it-it": "it",
|
|
748
|
+
"it-ch": "it",
|
|
749
|
+
"ja-jp": "ja",
|
|
750
|
+
jp: "ja",
|
|
751
|
+
"ko-kr": "ko",
|
|
752
|
+
kr: "ko",
|
|
753
|
+
"ru-ru": "ru",
|
|
754
|
+
nb: "no"
|
|
755
|
+
};
|
|
756
|
+
});
|
|
757
|
+
|
|
687
758
|
// src/core/engine.ts
|
|
688
759
|
class TranslationEngine {
|
|
689
760
|
options;
|
|
@@ -693,7 +764,7 @@ class TranslationEngine {
|
|
|
693
764
|
isReady = false;
|
|
694
765
|
translating = false;
|
|
695
766
|
pendingQueue = [];
|
|
696
|
-
|
|
767
|
+
maxSentenceLength = 512;
|
|
697
768
|
constructor(options = {}) {
|
|
698
769
|
this.options = options;
|
|
699
770
|
}
|
|
@@ -705,7 +776,7 @@ class TranslationEngine {
|
|
|
705
776
|
"beam-size": 1,
|
|
706
777
|
normalize: 1,
|
|
707
778
|
"word-penalty": 0,
|
|
708
|
-
"max-length-break":
|
|
779
|
+
"max-length-break": 512,
|
|
709
780
|
"mini-batch-words": 1024,
|
|
710
781
|
workspace: 128,
|
|
711
782
|
"max-length-factor": 2,
|
|
@@ -717,7 +788,6 @@ class TranslationEngine {
|
|
|
717
788
|
alignment: "soft"
|
|
718
789
|
};
|
|
719
790
|
const mergedConfig = { ...defaultConfig, ...config };
|
|
720
|
-
this.maxLengthBreak = mergedConfig["max-length-break"] || 128;
|
|
721
791
|
const MODEL_FILE_ALIGNMENTS = {
|
|
722
792
|
model: 256,
|
|
723
793
|
lex: 64,
|
|
@@ -755,7 +825,7 @@ class TranslationEngine {
|
|
|
755
825
|
const effectiveOptions = forceHtml ? { ...options, html: true } : options;
|
|
756
826
|
let translation;
|
|
757
827
|
try {
|
|
758
|
-
if (cleanText.length > this.
|
|
828
|
+
if (cleanText.length > this.maxSentenceLength) {
|
|
759
829
|
translation = this._translateLongText(cleanText, effectiveOptions);
|
|
760
830
|
} else {
|
|
761
831
|
translation = this._translateInternal(cleanText, effectiveOptions);
|
|
@@ -848,6 +918,29 @@ class TranslationEngine {
|
|
|
848
918
|
const errorMsg = error2.message.toLowerCase();
|
|
849
919
|
return fatalPatterns.some((pattern) => errorMsg.includes(pattern));
|
|
850
920
|
}
|
|
921
|
+
_getMappedSeparator(sep, targetLang) {
|
|
922
|
+
if (!targetLang)
|
|
923
|
+
return sep;
|
|
924
|
+
const isTargetCJK = isCJKCode(targetLang);
|
|
925
|
+
const map = {
|
|
926
|
+
". ": { cjk: "。", nonCjk: ". " },
|
|
927
|
+
"。": { cjk: "。", nonCjk: ". " },
|
|
928
|
+
"!": { cjk: "!", nonCjk: "! " },
|
|
929
|
+
"!": { cjk: "!", nonCjk: "! " },
|
|
930
|
+
"?": { cjk: "?", nonCjk: "? " },
|
|
931
|
+
"?": { cjk: "?", nonCjk: "? " },
|
|
932
|
+
"; ": { cjk: ";", nonCjk: "; " },
|
|
933
|
+
";": { cjk: ";", nonCjk: "; " },
|
|
934
|
+
":": { cjk: ":", nonCjk: ": " },
|
|
935
|
+
": ": { cjk: ":", nonCjk: ": " },
|
|
936
|
+
",": { cjk: ",", nonCjk: ", " },
|
|
937
|
+
", ": { cjk: ",", nonCjk: ", " }
|
|
938
|
+
};
|
|
939
|
+
if (sep in map) {
|
|
940
|
+
return isTargetCJK ? map[sep].cjk : map[sep].nonCjk;
|
|
941
|
+
}
|
|
942
|
+
return sep;
|
|
943
|
+
}
|
|
851
944
|
_translateLongText(text, options = {}) {
|
|
852
945
|
const separators = [
|
|
853
946
|
`
|
|
@@ -882,24 +975,50 @@ class TranslationEngine {
|
|
|
882
975
|
bestSep = sep;
|
|
883
976
|
bestParts = parts;
|
|
884
977
|
}
|
|
885
|
-
if (maxLen <= this.
|
|
978
|
+
if (maxLen <= this.maxSentenceLength) {
|
|
886
979
|
break;
|
|
887
980
|
}
|
|
888
981
|
}
|
|
889
982
|
}
|
|
890
983
|
if (bestParts.length <= 1) {
|
|
891
|
-
bestParts = this.
|
|
984
|
+
bestParts = this._chunkByWordBoundary(text, this.maxSentenceLength);
|
|
892
985
|
bestSep = "";
|
|
893
986
|
}
|
|
894
987
|
const results = bestParts.map((part) => {
|
|
895
988
|
if (!part.trim())
|
|
896
989
|
return part;
|
|
897
|
-
if (part.length > this.
|
|
990
|
+
if (part.length > this.maxSentenceLength) {
|
|
898
991
|
return this._translateLongText(part, options);
|
|
899
992
|
}
|
|
900
993
|
return this._translateInternal(part, options);
|
|
901
994
|
});
|
|
902
|
-
|
|
995
|
+
const targetSep = this._getMappedSeparator(bestSep, this.options.targetLang);
|
|
996
|
+
return results.join(targetSep);
|
|
997
|
+
}
|
|
998
|
+
_chunkByWordBoundary(text, limit) {
|
|
999
|
+
const parts = text.split(/(\s+)/);
|
|
1000
|
+
const chunks = [];
|
|
1001
|
+
let currentChunk = "";
|
|
1002
|
+
for (const part of parts) {
|
|
1003
|
+
if (currentChunk.length + part.length <= limit) {
|
|
1004
|
+
currentChunk += part;
|
|
1005
|
+
} else {
|
|
1006
|
+
if (currentChunk.length > 0) {
|
|
1007
|
+
chunks.push(currentChunk);
|
|
1008
|
+
currentChunk = "";
|
|
1009
|
+
}
|
|
1010
|
+
if (part.length > limit) {
|
|
1011
|
+
const subChunks = this._chunkByLength(part, limit);
|
|
1012
|
+
chunks.push(...subChunks);
|
|
1013
|
+
} else {
|
|
1014
|
+
currentChunk = part;
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
}
|
|
1018
|
+
if (currentChunk.length > 0) {
|
|
1019
|
+
chunks.push(currentChunk);
|
|
1020
|
+
}
|
|
1021
|
+
return chunks;
|
|
903
1022
|
}
|
|
904
1023
|
_chunkByLength(text, chunkSize) {
|
|
905
1024
|
if (chunkSize <= 0)
|
|
@@ -971,6 +1090,9 @@ class TranslationEngine {
|
|
|
971
1090
|
}
|
|
972
1091
|
}
|
|
973
1092
|
}
|
|
1093
|
+
var init_engine = __esm(() => {
|
|
1094
|
+
init_lang_alias();
|
|
1095
|
+
});
|
|
974
1096
|
|
|
975
1097
|
// src/lib/bergamot/bergamot-translator.js
|
|
976
1098
|
var require_bergamot_translator = __commonJS((exports, module) => {
|
|
@@ -5106,15 +5228,16 @@ function bcp47Normalize(code) {
|
|
|
5106
5228
|
return code.toLowerCase();
|
|
5107
5229
|
}
|
|
5108
5230
|
}
|
|
5109
|
-
function
|
|
5110
|
-
|
|
5111
|
-
return null;
|
|
5112
|
-
}
|
|
5231
|
+
function detectPureCjkLanguage(text, startIndex = 0) {
|
|
5232
|
+
const limit = Math.min(text.length, startIndex + 2000);
|
|
5113
5233
|
let hasHan = false;
|
|
5114
5234
|
let hasKana = false;
|
|
5115
5235
|
let hasHangul = false;
|
|
5116
|
-
for (
|
|
5117
|
-
const code =
|
|
5236
|
+
for (let i = startIndex;i < limit; i++) {
|
|
5237
|
+
const code = text.charCodeAt(i);
|
|
5238
|
+
if (code >= 65 && code <= 90 || code >= 97 && code <= 122) {
|
|
5239
|
+
return null;
|
|
5240
|
+
}
|
|
5118
5241
|
if (code >= 12352 && code <= 12543) {
|
|
5119
5242
|
hasKana = true;
|
|
5120
5243
|
continue;
|
|
@@ -5127,16 +5250,6 @@ function detectShortCjkLanguage(text) {
|
|
|
5127
5250
|
hasHan = true;
|
|
5128
5251
|
continue;
|
|
5129
5252
|
}
|
|
5130
|
-
if (code >= 65 && code <= 90 || code >= 97 && code <= 122) {
|
|
5131
|
-
return null;
|
|
5132
|
-
}
|
|
5133
|
-
if (code >= 48 && code <= 57 || code <= 127) {
|
|
5134
|
-
continue;
|
|
5135
|
-
}
|
|
5136
|
-
if (code >= 12288 && code <= 12351) {
|
|
5137
|
-
continue;
|
|
5138
|
-
}
|
|
5139
|
-
return null;
|
|
5140
5253
|
}
|
|
5141
5254
|
if (hasKana)
|
|
5142
5255
|
return "ja";
|
|
@@ -5146,21 +5259,29 @@ function detectShortCjkLanguage(text) {
|
|
|
5146
5259
|
return "zh-Hans";
|
|
5147
5260
|
return null;
|
|
5148
5261
|
}
|
|
5262
|
+
function getValidContentStartIndex(text) {
|
|
5263
|
+
const match = text.match(/^[^\p{L}\p{N}]+/u);
|
|
5264
|
+
return match ? match[0].length : 0;
|
|
5265
|
+
}
|
|
5149
5266
|
async function detectLanguage(text, maxBytes = MAX_DETECTION_BYTES) {
|
|
5150
5267
|
if (!text) {
|
|
5151
5268
|
return "";
|
|
5152
5269
|
}
|
|
5153
|
-
const
|
|
5154
|
-
if (
|
|
5155
|
-
return
|
|
5270
|
+
const startIndex = getValidContentStartIndex(text);
|
|
5271
|
+
if (startIndex >= text.length)
|
|
5272
|
+
return "en";
|
|
5273
|
+
const pureCjk = detectPureCjkLanguage(text, startIndex);
|
|
5274
|
+
if (pureCjk) {
|
|
5275
|
+
return pureCjk;
|
|
5156
5276
|
}
|
|
5157
5277
|
await initCLD();
|
|
5278
|
+
const cleanText = text.slice(startIndex);
|
|
5158
5279
|
try {
|
|
5159
|
-
const result = detectLanguageWithCLD(
|
|
5280
|
+
const result = detectLanguageWithCLD(cleanText, false, maxBytes);
|
|
5160
5281
|
return bcp47Normalize(result.language);
|
|
5161
5282
|
} catch (error2) {
|
|
5162
5283
|
warn(`Language detection failed: ${error2}`);
|
|
5163
|
-
handleCldError(error2, { text, operation: "detectLanguage" });
|
|
5284
|
+
handleCldError(error2, { text: cleanText, operation: "detectLanguage" });
|
|
5164
5285
|
return "en";
|
|
5165
5286
|
}
|
|
5166
5287
|
}
|
|
@@ -5168,9 +5289,17 @@ async function detectLanguageWithConfidence(text, minConfidence = DEFAULT_CONFID
|
|
|
5168
5289
|
if (!text) {
|
|
5169
5290
|
return { language: "", confidence: 0 };
|
|
5170
5291
|
}
|
|
5292
|
+
const startIndex = getValidContentStartIndex(text);
|
|
5293
|
+
if (startIndex >= text.length)
|
|
5294
|
+
return { language: "en", confidence: 0 };
|
|
5295
|
+
const pureCjk = detectPureCjkLanguage(text, startIndex);
|
|
5296
|
+
if (pureCjk) {
|
|
5297
|
+
return { language: pureCjk, confidence: 1 };
|
|
5298
|
+
}
|
|
5171
5299
|
await initCLD();
|
|
5300
|
+
const cleanText = text.slice(startIndex);
|
|
5172
5301
|
try {
|
|
5173
|
-
const result = detectLanguageWithCLD(
|
|
5302
|
+
const result = detectLanguageWithCLD(cleanText, false, maxBytes);
|
|
5174
5303
|
const confidence = result.percentScore / 100;
|
|
5175
5304
|
if (confidence < minConfidence) {
|
|
5176
5305
|
return { language: "", confidence };
|
|
@@ -5181,7 +5310,7 @@ async function detectLanguageWithConfidence(text, minConfidence = DEFAULT_CONFID
|
|
|
5181
5310
|
};
|
|
5182
5311
|
} catch (error2) {
|
|
5183
5312
|
warn(`Language detection with confidence failed: ${error2}`);
|
|
5184
|
-
handleCldError(error2, { text, operation: "detectLanguageWithConfidence" });
|
|
5313
|
+
handleCldError(error2, { text: cleanText, operation: "detectLanguageWithConfidence" });
|
|
5185
5314
|
return { language: "en", confidence: 0 };
|
|
5186
5315
|
}
|
|
5187
5316
|
}
|
|
@@ -5220,9 +5349,6 @@ function getScriptType(text) {
|
|
|
5220
5349
|
return "Latin";
|
|
5221
5350
|
return "Other";
|
|
5222
5351
|
}
|
|
5223
|
-
function isCJKLanguage(lang) {
|
|
5224
|
-
return ["zh", "zh-Hans", "zh-Hant", "ja", "ko"].includes(lang) || lang.startsWith("zh-");
|
|
5225
|
-
}
|
|
5226
5352
|
async function detectMultipleLanguages(text) {
|
|
5227
5353
|
return detectMultipleLanguagesWithThreshold(text, DEFAULT_CONFIDENCE_THRESHOLD);
|
|
5228
5354
|
}
|
|
@@ -5260,7 +5386,7 @@ async function detectMultipleLanguagesWithThreshold(text, threshold) {
|
|
|
5260
5386
|
finalLang = detectedLang;
|
|
5261
5387
|
usedLogic = "confidence";
|
|
5262
5388
|
} else {
|
|
5263
|
-
if (scriptType === "Latin" &&
|
|
5389
|
+
if (scriptType === "Latin" && isCJKCode(effectiveFallback)) {
|
|
5264
5390
|
if (detectedLang && detectedLang !== "un") {
|
|
5265
5391
|
finalLang = detectedLang;
|
|
5266
5392
|
usedLogic = "script-override-latin";
|
|
@@ -5268,7 +5394,7 @@ async function detectMultipleLanguagesWithThreshold(text, threshold) {
|
|
|
5268
5394
|
finalLang = "en";
|
|
5269
5395
|
usedLogic = "script-override-en";
|
|
5270
5396
|
}
|
|
5271
|
-
} else if (scriptType === "CJK" && !
|
|
5397
|
+
} else if (scriptType === "CJK" && !isCJKCode(effectiveFallback)) {
|
|
5272
5398
|
if (detectedLang && detectedLang !== "un") {
|
|
5273
5399
|
finalLang = detectedLang;
|
|
5274
5400
|
usedLogic = "script-override-cjk";
|
|
@@ -5345,8 +5471,9 @@ function limitLanguages(segments, originalText, maxLangs) {
|
|
|
5345
5471
|
debug(`limitLanguages: reduced to ${maxLangs} languages, ${result.length} segments`);
|
|
5346
5472
|
return result;
|
|
5347
5473
|
}
|
|
5348
|
-
var import_cld2, DEFAULT_CONFIDENCE_THRESHOLD = 0.5, MAXIMUM_LANGUAGES_IN_ONE_TEXT = 2, MAX_DETECTION_BYTES =
|
|
5474
|
+
var import_cld2, DEFAULT_CONFIDENCE_THRESHOLD = 0.5, MAXIMUM_LANGUAGES_IN_ONE_TEXT = 2, MAX_DETECTION_BYTES = 511, MAX_FALLBACK_DETECTION_BYTES = 1023, cldModule = null, initPromise = null;
|
|
5349
5475
|
var init_detector = __esm(() => {
|
|
5476
|
+
init_lang_alias();
|
|
5350
5477
|
init_cld2();
|
|
5351
5478
|
init_logger();
|
|
5352
5479
|
import_cld2 = __toESM(require_cld2(), 1);
|
|
@@ -5527,7 +5654,7 @@ async function translateWithPivot(fromLang, toLang, text, isHTML = false) {
|
|
|
5527
5654
|
if (fromLang !== "auto" && fromLang === toLang) {
|
|
5528
5655
|
return text;
|
|
5529
5656
|
}
|
|
5530
|
-
if (fromLang !== "auto" && text.length <=
|
|
5657
|
+
if (fromLang !== "auto" && text.length <= 512) {
|
|
5531
5658
|
return translateSegment(fromLang, toLang, text, isHTML);
|
|
5532
5659
|
}
|
|
5533
5660
|
const config2 = getConfig();
|
|
@@ -5548,7 +5675,7 @@ async function translateWithPivot(fromLang, toLang, text, isHTML = false) {
|
|
|
5548
5675
|
if (effectiveFromLang === toLang) {
|
|
5549
5676
|
return text;
|
|
5550
5677
|
}
|
|
5551
|
-
if (text.length > config2.
|
|
5678
|
+
if (text.length > config2.maxSentenceLength && !isHTML) {
|
|
5552
5679
|
return translateLongText(effectiveFromLang, toLang, text);
|
|
5553
5680
|
}
|
|
5554
5681
|
return translateSegment(effectiveFromLang, toLang, text, isHTML);
|
|
@@ -5612,7 +5739,8 @@ function cleanupAllEngines() {
|
|
|
5612
5739
|
info("All engines cleaned up successfully");
|
|
5613
5740
|
}
|
|
5614
5741
|
var import_bergamot_translator, engines, loadingPromises;
|
|
5615
|
-
var
|
|
5742
|
+
var init_engine2 = __esm(() => {
|
|
5743
|
+
init_engine();
|
|
5616
5744
|
init_factory();
|
|
5617
5745
|
init_config();
|
|
5618
5746
|
init_bergamot_translator();
|
|
@@ -5636,7 +5764,7 @@ __export(exports_services, {
|
|
|
5636
5764
|
cleanupAllEngines: () => cleanupAllEngines
|
|
5637
5765
|
});
|
|
5638
5766
|
var init_services = __esm(() => {
|
|
5639
|
-
|
|
5767
|
+
init_engine2();
|
|
5640
5768
|
init_detector();
|
|
5641
5769
|
});
|
|
5642
5770
|
|
|
@@ -213694,71 +213822,6 @@ var require_dist4 = __commonJS((exports) => {
|
|
|
213694
213822
|
__exportStar(require_dist3(), exports);
|
|
213695
213823
|
});
|
|
213696
213824
|
|
|
213697
|
-
// src/utils/lang-alias.ts
|
|
213698
|
-
function NormalizeLanguageCode(code) {
|
|
213699
|
-
if (!code)
|
|
213700
|
-
return "";
|
|
213701
|
-
const normalized = code.toLowerCase().replace(/_/g, "-");
|
|
213702
|
-
if (languageAliases[normalized]) {
|
|
213703
|
-
return languageAliases[normalized];
|
|
213704
|
-
}
|
|
213705
|
-
const mainCode = normalized.split("-")[0];
|
|
213706
|
-
if (languageAliases[mainCode]) {
|
|
213707
|
-
return languageAliases[mainCode];
|
|
213708
|
-
}
|
|
213709
|
-
return mainCode;
|
|
213710
|
-
}
|
|
213711
|
-
var languageAliases;
|
|
213712
|
-
var init_lang_alias = __esm(() => {
|
|
213713
|
-
languageAliases = {
|
|
213714
|
-
zh: "zh-Hans",
|
|
213715
|
-
"zh-cn": "zh-Hans",
|
|
213716
|
-
"zh-sg": "zh-Hans",
|
|
213717
|
-
"zh-hans": "zh-Hans",
|
|
213718
|
-
cmn: "zh-Hans",
|
|
213719
|
-
chinese: "zh-Hans",
|
|
213720
|
-
"zh-tw": "zh-Hant",
|
|
213721
|
-
"zh-hk": "zh-Hant",
|
|
213722
|
-
"zh-mo": "zh-Hant",
|
|
213723
|
-
"zh-hant": "zh-Hant",
|
|
213724
|
-
cht: "zh-Hant",
|
|
213725
|
-
"en-us": "en",
|
|
213726
|
-
"en-gb": "en",
|
|
213727
|
-
"en-au": "en",
|
|
213728
|
-
"en-ca": "en",
|
|
213729
|
-
"en-nz": "en",
|
|
213730
|
-
"en-ie": "en",
|
|
213731
|
-
"en-za": "en",
|
|
213732
|
-
"en-jm": "en",
|
|
213733
|
-
"en-bz": "en",
|
|
213734
|
-
"en-tt": "en",
|
|
213735
|
-
"fr-fr": "fr",
|
|
213736
|
-
"fr-ca": "fr",
|
|
213737
|
-
"fr-be": "fr",
|
|
213738
|
-
"fr-ch": "fr",
|
|
213739
|
-
"es-es": "es",
|
|
213740
|
-
"es-mx": "es",
|
|
213741
|
-
"es-ar": "es",
|
|
213742
|
-
"es-co": "es",
|
|
213743
|
-
"es-cl": "es",
|
|
213744
|
-
"es-pe": "es",
|
|
213745
|
-
"es-ve": "es",
|
|
213746
|
-
"pt-pt": "pt",
|
|
213747
|
-
"pt-br": "pt",
|
|
213748
|
-
"de-de": "de",
|
|
213749
|
-
"de-at": "de",
|
|
213750
|
-
"de-ch": "de",
|
|
213751
|
-
"it-it": "it",
|
|
213752
|
-
"it-ch": "it",
|
|
213753
|
-
"ja-jp": "ja",
|
|
213754
|
-
jp: "ja",
|
|
213755
|
-
"ko-kr": "ko",
|
|
213756
|
-
kr: "ko",
|
|
213757
|
-
"ru-ru": "ru",
|
|
213758
|
-
nb: "no"
|
|
213759
|
-
};
|
|
213760
|
-
});
|
|
213761
|
-
|
|
213762
213825
|
// src/utils/port.ts
|
|
213763
213826
|
import net from "net";
|
|
213764
213827
|
async function getFreePort() {
|
|
@@ -213794,6 +213857,7 @@ var init_memory = () => {};
|
|
|
213794
213857
|
// src/utils/index.ts
|
|
213795
213858
|
var exports_utils = {};
|
|
213796
213859
|
__export(exports_utils, {
|
|
213860
|
+
isCJKCode: () => isCJKCode,
|
|
213797
213861
|
getLargestVersion: () => getLargestVersion,
|
|
213798
213862
|
getFreePort: () => getFreePort,
|
|
213799
213863
|
getAvailableMemoryMB: () => getAvailableMemoryMB,
|
|
@@ -213814,7 +213878,7 @@ __export(exports_version, {
|
|
|
213814
213878
|
function getVersion() {
|
|
213815
213879
|
return VERSION;
|
|
213816
213880
|
}
|
|
213817
|
-
var VERSION = "4.0.
|
|
213881
|
+
var VERSION = "4.0.27";
|
|
213818
213882
|
|
|
213819
213883
|
// src/server/index.ts
|
|
213820
213884
|
init_config();
|
|
@@ -214378,9 +214442,69 @@ GoogleController = __legacyDecorateClassTS([
|
|
|
214378
214442
|
import_tsoa7.Tags("Compatible APIs")
|
|
214379
214443
|
], GoogleController);
|
|
214380
214444
|
|
|
214381
|
-
// src/controllers/plugins/
|
|
214445
|
+
// src/controllers/plugins/deeplx.controller.ts
|
|
214382
214446
|
var import_tsoa8 = __toESM(require_dist4(), 1);
|
|
214383
|
-
class
|
|
214447
|
+
class DeeplxController extends import_tsoa8.Controller {
|
|
214448
|
+
async translate(body, authorization, tokenQuery) {
|
|
214449
|
+
const { NormalizeLanguageCode: NormalizeLanguageCode2 } = await Promise.resolve().then(() => (init_utils(), exports_utils));
|
|
214450
|
+
const { translateWithPivot: translateWithPivot2 } = await Promise.resolve().then(() => (init_services(), exports_services));
|
|
214451
|
+
const { getConfig: getConfig2 } = await Promise.resolve().then(() => (init_config(), exports_config));
|
|
214452
|
+
const config2 = getConfig2();
|
|
214453
|
+
const apiToken = config2.apiToken;
|
|
214454
|
+
if (apiToken) {
|
|
214455
|
+
let token = "";
|
|
214456
|
+
if (authorization) {
|
|
214457
|
+
if (authorization.startsWith("Bearer ")) {
|
|
214458
|
+
token = authorization.replace("Bearer ", "");
|
|
214459
|
+
} else {
|
|
214460
|
+
token = authorization;
|
|
214461
|
+
}
|
|
214462
|
+
} else if (tokenQuery) {
|
|
214463
|
+
token = tokenQuery;
|
|
214464
|
+
}
|
|
214465
|
+
if (token !== apiToken) {
|
|
214466
|
+
this.setStatus(401);
|
|
214467
|
+
throw new Error("Unauthorized");
|
|
214468
|
+
}
|
|
214469
|
+
}
|
|
214470
|
+
const sourceLang = body.source_lang ? NormalizeLanguageCode2(body.source_lang) : "auto";
|
|
214471
|
+
const targetLang = NormalizeLanguageCode2(body.target_lang);
|
|
214472
|
+
const text = body.text;
|
|
214473
|
+
const result = await translateWithPivot2(sourceLang, targetLang, text, false);
|
|
214474
|
+
const id = Math.floor(Math.random() * 10000000000);
|
|
214475
|
+
return {
|
|
214476
|
+
alternatives: [],
|
|
214477
|
+
code: 200,
|
|
214478
|
+
data: result,
|
|
214479
|
+
id,
|
|
214480
|
+
method: "Free",
|
|
214481
|
+
source_lang: sourceLang.toUpperCase(),
|
|
214482
|
+
target_lang: targetLang.toUpperCase()
|
|
214483
|
+
};
|
|
214484
|
+
}
|
|
214485
|
+
}
|
|
214486
|
+
__legacyDecorateClassTS([
|
|
214487
|
+
import_tsoa8.Post("/"),
|
|
214488
|
+
import_tsoa8.SuccessResponse("200", "Success"),
|
|
214489
|
+
__legacyDecorateParamTS(0, import_tsoa8.Body()),
|
|
214490
|
+
__legacyDecorateParamTS(1, import_tsoa8.Header("Authorization")),
|
|
214491
|
+
__legacyDecorateParamTS(2, import_tsoa8.Query("token")),
|
|
214492
|
+
__legacyMetadataTS("design:type", Function),
|
|
214493
|
+
__legacyMetadataTS("design:paramtypes", [
|
|
214494
|
+
typeof DeeplxTranslateRequest === "undefined" ? Object : DeeplxTranslateRequest,
|
|
214495
|
+
String,
|
|
214496
|
+
String
|
|
214497
|
+
]),
|
|
214498
|
+
__legacyMetadataTS("design:returntype", typeof Promise === "undefined" ? Object : Promise)
|
|
214499
|
+
], DeeplxController.prototype, "translate", null);
|
|
214500
|
+
DeeplxController = __legacyDecorateClassTS([
|
|
214501
|
+
import_tsoa8.Route("deeplx"),
|
|
214502
|
+
import_tsoa8.Tags("Compatible APIs")
|
|
214503
|
+
], DeeplxController);
|
|
214504
|
+
|
|
214505
|
+
// src/controllers/plugins/deepl.controller.ts
|
|
214506
|
+
var import_tsoa9 = __toESM(require_dist4(), 1);
|
|
214507
|
+
class DeeplController extends import_tsoa9.Controller {
|
|
214384
214508
|
async translate(body, authorization) {
|
|
214385
214509
|
const { NormalizeLanguageCode: NormalizeLanguageCode2 } = await Promise.resolve().then(() => (init_utils(), exports_utils));
|
|
214386
214510
|
const { translateWithPivot: translateWithPivot2 } = await Promise.resolve().then(() => (init_services(), exports_services));
|
|
@@ -214428,10 +214552,10 @@ class DeeplController extends import_tsoa8.Controller {
|
|
|
214428
214552
|
}
|
|
214429
214553
|
}
|
|
214430
214554
|
__legacyDecorateClassTS([
|
|
214431
|
-
|
|
214432
|
-
|
|
214433
|
-
__legacyDecorateParamTS(0,
|
|
214434
|
-
__legacyDecorateParamTS(1,
|
|
214555
|
+
import_tsoa9.Post("/"),
|
|
214556
|
+
import_tsoa9.SuccessResponse("200", "Success"),
|
|
214557
|
+
__legacyDecorateParamTS(0, import_tsoa9.Body()),
|
|
214558
|
+
__legacyDecorateParamTS(1, import_tsoa9.Header("Authorization")),
|
|
214435
214559
|
__legacyMetadataTS("design:type", Function),
|
|
214436
214560
|
__legacyMetadataTS("design:paramtypes", [
|
|
214437
214561
|
typeof DeeplTranslateRequest === "undefined" ? Object : DeeplTranslateRequest,
|
|
@@ -214440,8 +214564,8 @@ __legacyDecorateClassTS([
|
|
|
214440
214564
|
__legacyMetadataTS("design:returntype", typeof Promise === "undefined" ? Object : Promise)
|
|
214441
214565
|
], DeeplController.prototype, "translate", null);
|
|
214442
214566
|
DeeplController = __legacyDecorateClassTS([
|
|
214443
|
-
|
|
214444
|
-
|
|
214567
|
+
import_tsoa9.Route("deepl"),
|
|
214568
|
+
import_tsoa9.Tags("Compatible APIs")
|
|
214445
214569
|
], DeeplController);
|
|
214446
214570
|
|
|
214447
214571
|
// src/generated/routes.ts
|
|
@@ -214611,6 +214735,28 @@ var models = {
|
|
|
214611
214735
|
},
|
|
214612
214736
|
additionalProperties: false
|
|
214613
214737
|
},
|
|
214738
|
+
DeeplxTranslateResponse: {
|
|
214739
|
+
dataType: "refObject",
|
|
214740
|
+
properties: {
|
|
214741
|
+
alternatives: { dataType: "array", array: { dataType: "string" }, required: true },
|
|
214742
|
+
code: { dataType: "double", required: true },
|
|
214743
|
+
data: { dataType: "string", required: true },
|
|
214744
|
+
id: { dataType: "double", required: true },
|
|
214745
|
+
method: { dataType: "string", required: true },
|
|
214746
|
+
source_lang: { dataType: "string", required: true },
|
|
214747
|
+
target_lang: { dataType: "string", required: true }
|
|
214748
|
+
},
|
|
214749
|
+
additionalProperties: false
|
|
214750
|
+
},
|
|
214751
|
+
DeeplxTranslateRequest: {
|
|
214752
|
+
dataType: "refObject",
|
|
214753
|
+
properties: {
|
|
214754
|
+
text: { dataType: "string", required: true },
|
|
214755
|
+
source_lang: { dataType: "string", required: true },
|
|
214756
|
+
target_lang: { dataType: "string", required: true }
|
|
214757
|
+
},
|
|
214758
|
+
additionalProperties: false
|
|
214759
|
+
},
|
|
214614
214760
|
DeeplTranslation: {
|
|
214615
214761
|
dataType: "refObject",
|
|
214616
214762
|
properties: {
|
|
@@ -214892,6 +215038,28 @@ function RegisterRoutes(app) {
|
|
|
214892
215038
|
return next(err);
|
|
214893
215039
|
}
|
|
214894
215040
|
});
|
|
215041
|
+
const argsDeeplxController_translate = {
|
|
215042
|
+
body: { in: "body", name: "body", required: true, ref: "DeeplxTranslateRequest" },
|
|
215043
|
+
authorization: { in: "header", name: "Authorization", dataType: "string" },
|
|
215044
|
+
tokenQuery: { in: "query", name: "token", dataType: "string" }
|
|
215045
|
+
};
|
|
215046
|
+
app.post("/deeplx", ...import_runtime.fetchMiddlewares(DeeplxController), ...import_runtime.fetchMiddlewares(DeeplxController.prototype.translate), async function DeeplxController_translate(request, response, next) {
|
|
215047
|
+
let validatedArgs = [];
|
|
215048
|
+
try {
|
|
215049
|
+
validatedArgs = templateService.getValidatedArgs({ args: argsDeeplxController_translate, request, response });
|
|
215050
|
+
const controller = new DeeplxController;
|
|
215051
|
+
await templateService.apiHandler({
|
|
215052
|
+
methodName: "translate",
|
|
215053
|
+
controller,
|
|
215054
|
+
response,
|
|
215055
|
+
next,
|
|
215056
|
+
validatedArgs,
|
|
215057
|
+
successStatus: 200
|
|
215058
|
+
});
|
|
215059
|
+
} catch (err) {
|
|
215060
|
+
return next(err);
|
|
215061
|
+
}
|
|
215062
|
+
});
|
|
214895
215063
|
const argsDeeplController_translate = {
|
|
214896
215064
|
body: { in: "body", name: "body", required: true, ref: "DeeplTranslateRequest" },
|
|
214897
215065
|
authorization: { in: "header", name: "Authorization", dataType: "string" }
|
|
@@ -215378,6 +215546,67 @@ var swagger_default = {
|
|
|
215378
215546
|
type: "object",
|
|
215379
215547
|
additionalProperties: false
|
|
215380
215548
|
},
|
|
215549
|
+
DeeplxTranslateResponse: {
|
|
215550
|
+
properties: {
|
|
215551
|
+
alternatives: {
|
|
215552
|
+
items: {
|
|
215553
|
+
type: "string"
|
|
215554
|
+
},
|
|
215555
|
+
type: "array"
|
|
215556
|
+
},
|
|
215557
|
+
code: {
|
|
215558
|
+
type: "number",
|
|
215559
|
+
format: "double"
|
|
215560
|
+
},
|
|
215561
|
+
data: {
|
|
215562
|
+
type: "string"
|
|
215563
|
+
},
|
|
215564
|
+
id: {
|
|
215565
|
+
type: "number",
|
|
215566
|
+
format: "double"
|
|
215567
|
+
},
|
|
215568
|
+
method: {
|
|
215569
|
+
type: "string"
|
|
215570
|
+
},
|
|
215571
|
+
source_lang: {
|
|
215572
|
+
type: "string"
|
|
215573
|
+
},
|
|
215574
|
+
target_lang: {
|
|
215575
|
+
type: "string"
|
|
215576
|
+
}
|
|
215577
|
+
},
|
|
215578
|
+
required: [
|
|
215579
|
+
"alternatives",
|
|
215580
|
+
"code",
|
|
215581
|
+
"data",
|
|
215582
|
+
"id",
|
|
215583
|
+
"method",
|
|
215584
|
+
"source_lang",
|
|
215585
|
+
"target_lang"
|
|
215586
|
+
],
|
|
215587
|
+
type: "object",
|
|
215588
|
+
additionalProperties: false
|
|
215589
|
+
},
|
|
215590
|
+
DeeplxTranslateRequest: {
|
|
215591
|
+
properties: {
|
|
215592
|
+
text: {
|
|
215593
|
+
type: "string"
|
|
215594
|
+
},
|
|
215595
|
+
source_lang: {
|
|
215596
|
+
type: "string"
|
|
215597
|
+
},
|
|
215598
|
+
target_lang: {
|
|
215599
|
+
type: "string"
|
|
215600
|
+
}
|
|
215601
|
+
},
|
|
215602
|
+
required: [
|
|
215603
|
+
"text",
|
|
215604
|
+
"source_lang",
|
|
215605
|
+
"target_lang"
|
|
215606
|
+
],
|
|
215607
|
+
type: "object",
|
|
215608
|
+
additionalProperties: false
|
|
215609
|
+
},
|
|
215381
215610
|
DeeplTranslation: {
|
|
215382
215611
|
properties: {
|
|
215383
215612
|
detected_source_language: {
|
|
@@ -215451,7 +215680,7 @@ var swagger_default = {
|
|
|
215451
215680
|
},
|
|
215452
215681
|
info: {
|
|
215453
215682
|
title: "MTranServer API",
|
|
215454
|
-
version: "4.0.
|
|
215683
|
+
version: "4.0.27",
|
|
215455
215684
|
description: "Translation server API",
|
|
215456
215685
|
license: {
|
|
215457
215686
|
name: "Apache-2.0"
|
|
@@ -215865,6 +216094,55 @@ var swagger_default = {
|
|
|
215865
216094
|
]
|
|
215866
216095
|
}
|
|
215867
216096
|
},
|
|
216097
|
+
"/deeplx": {
|
|
216098
|
+
post: {
|
|
216099
|
+
operationId: "Translate",
|
|
216100
|
+
responses: {
|
|
216101
|
+
"200": {
|
|
216102
|
+
description: "Success",
|
|
216103
|
+
content: {
|
|
216104
|
+
"application/json": {
|
|
216105
|
+
schema: {
|
|
216106
|
+
$ref: "#/components/schemas/DeeplxTranslateResponse"
|
|
216107
|
+
}
|
|
216108
|
+
}
|
|
216109
|
+
}
|
|
216110
|
+
}
|
|
216111
|
+
},
|
|
216112
|
+
tags: [
|
|
216113
|
+
"Compatible APIs"
|
|
216114
|
+
],
|
|
216115
|
+
security: [],
|
|
216116
|
+
parameters: [
|
|
216117
|
+
{
|
|
216118
|
+
in: "header",
|
|
216119
|
+
name: "Authorization",
|
|
216120
|
+
required: false,
|
|
216121
|
+
schema: {
|
|
216122
|
+
type: "string"
|
|
216123
|
+
}
|
|
216124
|
+
},
|
|
216125
|
+
{
|
|
216126
|
+
in: "query",
|
|
216127
|
+
name: "token",
|
|
216128
|
+
required: false,
|
|
216129
|
+
schema: {
|
|
216130
|
+
type: "string"
|
|
216131
|
+
}
|
|
216132
|
+
}
|
|
216133
|
+
],
|
|
216134
|
+
requestBody: {
|
|
216135
|
+
required: true,
|
|
216136
|
+
content: {
|
|
216137
|
+
"application/json": {
|
|
216138
|
+
schema: {
|
|
216139
|
+
$ref: "#/components/schemas/DeeplxTranslateRequest"
|
|
216140
|
+
}
|
|
216141
|
+
}
|
|
216142
|
+
}
|
|
216143
|
+
}
|
|
216144
|
+
}
|
|
216145
|
+
},
|
|
215868
216146
|
"/deepl": {
|
|
215869
216147
|
post: {
|
|
215870
216148
|
operationId: "Translate",
|
|
@@ -215931,7 +216209,7 @@ import { fileURLToPath as fileURLToPath3 } from "url";
|
|
|
215931
216209
|
var icon_default = "./icon-encyk9bj.png";
|
|
215932
216210
|
|
|
215933
216211
|
// ui/dist/index.html
|
|
215934
|
-
var dist_default = "./index-
|
|
216212
|
+
var dist_default = "./index-csm26kkw.html";
|
|
215935
216213
|
|
|
215936
216214
|
// ui/dist/.DS_Store
|
|
215937
216215
|
var __default = "./-cc07y4t8.DS_Store";
|
|
@@ -215939,8 +216217,8 @@ var __default = "./-cc07y4t8.DS_Store";
|
|
|
215939
216217
|
// ui/dist/assets/index-D-fF9r3Z.css
|
|
215940
216218
|
var index_D_fF9r3Z_default = "./index-D-fF9r3Z-r4yznc2q.css";
|
|
215941
216219
|
|
|
215942
|
-
// ui/dist/assets/index-
|
|
215943
|
-
var
|
|
216220
|
+
// ui/dist/assets/index-DAzz1C6Q.js
|
|
216221
|
+
var index_DAzz1C6Q_default = "./index-DAzz1C6Q-238q065m.js";
|
|
215944
216222
|
|
|
215945
216223
|
// src/assets/ui.ts
|
|
215946
216224
|
var assets = {
|
|
@@ -215948,7 +216226,7 @@ var assets = {
|
|
|
215948
216226
|
"/index.html": dist_default,
|
|
215949
216227
|
"/.DS_Store": __default,
|
|
215950
216228
|
"/assets/index-D-fF9r3Z.css": index_D_fF9r3Z_default,
|
|
215951
|
-
"/assets/index-
|
|
216229
|
+
"/assets/index-DAzz1C6Q.js": index_DAzz1C6Q_default
|
|
215952
216230
|
};
|
|
215953
216231
|
|
|
215954
216232
|
// src/middleware/ui.ts
|
|
@@ -216132,7 +216410,7 @@ async function startServer({ handleSignals = true } = {}) {
|
|
|
216132
216410
|
logToFile: current.logToFile,
|
|
216133
216411
|
logConsole: current.logConsole,
|
|
216134
216412
|
logRequests: current.logRequests,
|
|
216135
|
-
|
|
216413
|
+
maxSentenceLength: current.maxSentenceLength,
|
|
216136
216414
|
checkUpdate: current.checkUpdate,
|
|
216137
216415
|
cacheSize: current.cacheSize,
|
|
216138
216416
|
modelDir: current.modelDir,
|
|
@@ -216174,7 +216452,7 @@ async function startServer({ handleSignals = true } = {}) {
|
|
|
216174
216452
|
logToFile: toBool(input.logToFile, current.logToFile),
|
|
216175
216453
|
logConsole: toBool(input.logConsole, current.logConsole),
|
|
216176
216454
|
logRequests: toBool(input.logRequests, current.logRequests),
|
|
216177
|
-
|
|
216455
|
+
maxSentenceLength: toNumber(input.maxSentenceLength, current.maxSentenceLength),
|
|
216178
216456
|
checkUpdate: toBool(input.checkUpdate, current.checkUpdate),
|
|
216179
216457
|
cacheSize: toNumber(input.cacheSize, current.cacheSize),
|
|
216180
216458
|
modelDir: toString2(input.modelDir, current.modelDir),
|