mtranserver 4.0.31 → 4.0.32

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/index.js CHANGED
@@ -5557,10 +5557,10 @@ function formatChinesePunctuation(text, toLang, isHTML, enabled) {
5557
5557
  if (!enabled || isHTML || !toLang.startsWith("zh")) {
5558
5558
  return text;
5559
5559
  }
5560
- if (!zhPunctTest.test(text)) {
5560
+ if (!zhCommaTest.test(text)) {
5561
5561
  return text;
5562
5562
  }
5563
- return text.replace(zhPunctGlobal, (ch) => String.fromCharCode(ch.charCodeAt(0) + 65248));
5563
+ return text.replace(zhCommaGlobal, ",");
5564
5564
  }
5565
5565
  function needsPivotTranslation(fromLang, toLang) {
5566
5566
  if (fromLang === "en" || toLang === "en") {
@@ -5696,63 +5696,66 @@ async function translateSegment(fromLang, toLang, text, isHTML) {
5696
5696
  }
5697
5697
  async function translateWithPivot(fromLang, toLang, text, isHTML = false) {
5698
5698
  debug(`TranslateWithPivot: ${fromLang} -> ${toLang}, text length: ${text.length}, isHTML: ${isHTML}`);
5699
- const config2 = getConfig();
5700
- const shouldFullwidth = config2.fullwidthZhPunctuation ?? true;
5699
+ let config2 = null;
5700
+ let result = text;
5701
5701
  if (fromLang !== "auto" && fromLang === toLang) {
5702
- return formatChinesePunctuation(text, toLang, isHTML, shouldFullwidth);
5703
- }
5704
- if (fromLang !== "auto" && text.length <= 512) {
5705
- const translated = await translateSegment(fromLang, toLang, text, isHTML);
5706
- return formatChinesePunctuation(translated, toLang, isHTML, shouldFullwidth);
5707
- }
5708
- const segments = await detectMultipleLanguages(text);
5709
- if (segments.length <= 1) {
5710
- let effectiveFromLang;
5711
- if (segments.length === 1) {
5712
- effectiveFromLang = segments[0].language;
5713
- } else if (fromLang === "auto") {
5714
- const detected = await detectLanguage(text);
5715
- if (!detected) {
5716
- throw new Error("Failed to detect source language");
5717
- }
5718
- effectiveFromLang = detected;
5719
- } else {
5720
- effectiveFromLang = fromLang;
5721
- }
5722
- if (effectiveFromLang === toLang) {
5723
- return formatChinesePunctuation(text, toLang, isHTML, shouldFullwidth);
5724
- }
5725
- if (text.length > config2.maxSentenceLength && !isHTML) {
5726
- const translated2 = await translateLongText(effectiveFromLang, toLang, text);
5727
- return formatChinesePunctuation(translated2, toLang, isHTML, shouldFullwidth);
5728
- }
5729
- const translated = await translateSegment(effectiveFromLang, toLang, text, isHTML);
5730
- return formatChinesePunctuation(translated, toLang, isHTML, shouldFullwidth);
5731
- }
5732
- debug(`Detected ${segments.length} language segments`);
5733
- let result = "";
5734
- let lastEnd = 0;
5735
- for (const seg of segments) {
5736
- if (seg.start > lastEnd) {
5737
- result += text.substring(lastEnd, seg.start);
5738
- }
5739
- if (seg.language === toLang) {
5740
- result += seg.text;
5702
+ result = text;
5703
+ } else if (fromLang !== "auto" && text.length <= 512) {
5704
+ result = await translateSegment(fromLang, toLang, text, isHTML);
5705
+ } else {
5706
+ const segments = await detectMultipleLanguages(text);
5707
+ if (segments.length <= 1) {
5708
+ let effectiveFromLang;
5709
+ if (segments.length === 1) {
5710
+ effectiveFromLang = segments[0].language;
5711
+ } else if (fromLang === "auto") {
5712
+ const detected = await detectLanguage(text);
5713
+ if (!detected) {
5714
+ throw new Error("Failed to detect source language");
5715
+ }
5716
+ effectiveFromLang = detected;
5717
+ } else {
5718
+ effectiveFromLang = fromLang;
5719
+ }
5720
+ if (effectiveFromLang === toLang) {
5721
+ result = text;
5722
+ } else if (!isHTML) {
5723
+ config2 = config2 ?? getConfig();
5724
+ result = text.length > config2.maxSentenceLength ? await translateLongText(effectiveFromLang, toLang, text) : await translateSegment(effectiveFromLang, toLang, text, isHTML);
5725
+ } else {
5726
+ result = await translateSegment(effectiveFromLang, toLang, text, isHTML);
5727
+ }
5741
5728
  } else {
5742
- try {
5743
- const translated = await translateSegment(seg.language, toLang, seg.text, isHTML);
5744
- result += translated;
5745
- } catch (error2) {
5746
- error(`Failed to translate segment: ${error2}`);
5747
- result += seg.text;
5729
+ debug(`Detected ${segments.length} language segments`);
5730
+ result = "";
5731
+ let lastEnd = 0;
5732
+ for (const seg of segments) {
5733
+ if (seg.start > lastEnd) {
5734
+ result += text.substring(lastEnd, seg.start);
5735
+ }
5736
+ if (seg.language === toLang) {
5737
+ result += seg.text;
5738
+ } else {
5739
+ try {
5740
+ const translated = await translateSegment(seg.language, toLang, seg.text, isHTML);
5741
+ result += translated;
5742
+ } catch (error2) {
5743
+ error(`Failed to translate segment: ${error2}`);
5744
+ result += seg.text;
5745
+ }
5746
+ }
5747
+ lastEnd = seg.end;
5748
+ }
5749
+ if (lastEnd < text.length) {
5750
+ result += text.substring(lastEnd);
5748
5751
  }
5749
5752
  }
5750
- lastEnd = seg.end;
5751
5753
  }
5752
- if (lastEnd < text.length) {
5753
- result += text.substring(lastEnd);
5754
+ if (!toLang.startsWith("zh")) {
5755
+ return result;
5754
5756
  }
5755
- return formatChinesePunctuation(result, toLang, isHTML, shouldFullwidth);
5757
+ config2 = config2 ?? getConfig();
5758
+ return formatChinesePunctuation(result, toLang, isHTML, config2.fullwidthZhPunctuation);
5756
5759
  }
5757
5760
  async function translateLongText(fromLang, toLang, text) {
5758
5761
  debug(`Splitting long text (${text.length} chars) into sentences`);
@@ -5787,7 +5790,7 @@ function cleanupAllEngines() {
5787
5790
  engines.clear();
5788
5791
  info("All engines cleaned up successfully");
5789
5792
  }
5790
- var import_bergamot_translator, engines, loadingPromises, zhPunctTest, zhPunctGlobal;
5793
+ var import_bergamot_translator, engines, loadingPromises, zhCommaTest, zhCommaGlobal;
5791
5794
  var init_engine2 = __esm(() => {
5792
5795
  init_engine();
5793
5796
  init_factory();
@@ -5800,8 +5803,8 @@ var init_engine2 = __esm(() => {
5800
5803
  import_bergamot_translator = __toESM(require_bergamot_translator(), 1);
5801
5804
  engines = new Map;
5802
5805
  loadingPromises = new Map;
5803
- zhPunctTest = /[!-/:-@[-`{-~]/;
5804
- zhPunctGlobal = /[!-/:-@[-`{-~]/g;
5806
+ zhCommaTest = /,/;
5807
+ zhCommaGlobal = /,/g;
5805
5808
  });
5806
5809
 
5807
5810
  // src/services/index.ts
package/dist/main.js CHANGED
@@ -5558,10 +5558,10 @@ function formatChinesePunctuation(text, toLang, isHTML, enabled) {
5558
5558
  if (!enabled || isHTML || !toLang.startsWith("zh")) {
5559
5559
  return text;
5560
5560
  }
5561
- if (!zhPunctTest.test(text)) {
5561
+ if (!zhCommaTest.test(text)) {
5562
5562
  return text;
5563
5563
  }
5564
- return text.replace(zhPunctGlobal, (ch) => String.fromCharCode(ch.charCodeAt(0) + 65248));
5564
+ return text.replace(zhCommaGlobal, ",");
5565
5565
  }
5566
5566
  function needsPivotTranslation(fromLang, toLang) {
5567
5567
  if (fromLang === "en" || toLang === "en") {
@@ -5697,63 +5697,66 @@ async function translateSegment(fromLang, toLang, text, isHTML) {
5697
5697
  }
5698
5698
  async function translateWithPivot(fromLang, toLang, text, isHTML = false) {
5699
5699
  debug(`TranslateWithPivot: ${fromLang} -> ${toLang}, text length: ${text.length}, isHTML: ${isHTML}`);
5700
- const config2 = getConfig();
5701
- const shouldFullwidth = config2.fullwidthZhPunctuation ?? true;
5700
+ let config2 = null;
5701
+ let result = text;
5702
5702
  if (fromLang !== "auto" && fromLang === toLang) {
5703
- return formatChinesePunctuation(text, toLang, isHTML, shouldFullwidth);
5704
- }
5705
- if (fromLang !== "auto" && text.length <= 512) {
5706
- const translated = await translateSegment(fromLang, toLang, text, isHTML);
5707
- return formatChinesePunctuation(translated, toLang, isHTML, shouldFullwidth);
5708
- }
5709
- const segments = await detectMultipleLanguages(text);
5710
- if (segments.length <= 1) {
5711
- let effectiveFromLang;
5712
- if (segments.length === 1) {
5713
- effectiveFromLang = segments[0].language;
5714
- } else if (fromLang === "auto") {
5715
- const detected = await detectLanguage(text);
5716
- if (!detected) {
5717
- throw new Error("Failed to detect source language");
5718
- }
5719
- effectiveFromLang = detected;
5720
- } else {
5721
- effectiveFromLang = fromLang;
5722
- }
5723
- if (effectiveFromLang === toLang) {
5724
- return formatChinesePunctuation(text, toLang, isHTML, shouldFullwidth);
5725
- }
5726
- if (text.length > config2.maxSentenceLength && !isHTML) {
5727
- const translated2 = await translateLongText(effectiveFromLang, toLang, text);
5728
- return formatChinesePunctuation(translated2, toLang, isHTML, shouldFullwidth);
5729
- }
5730
- const translated = await translateSegment(effectiveFromLang, toLang, text, isHTML);
5731
- return formatChinesePunctuation(translated, toLang, isHTML, shouldFullwidth);
5732
- }
5733
- debug(`Detected ${segments.length} language segments`);
5734
- let result = "";
5735
- let lastEnd = 0;
5736
- for (const seg of segments) {
5737
- if (seg.start > lastEnd) {
5738
- result += text.substring(lastEnd, seg.start);
5739
- }
5740
- if (seg.language === toLang) {
5741
- result += seg.text;
5703
+ result = text;
5704
+ } else if (fromLang !== "auto" && text.length <= 512) {
5705
+ result = await translateSegment(fromLang, toLang, text, isHTML);
5706
+ } else {
5707
+ const segments = await detectMultipleLanguages(text);
5708
+ if (segments.length <= 1) {
5709
+ let effectiveFromLang;
5710
+ if (segments.length === 1) {
5711
+ effectiveFromLang = segments[0].language;
5712
+ } else if (fromLang === "auto") {
5713
+ const detected = await detectLanguage(text);
5714
+ if (!detected) {
5715
+ throw new Error("Failed to detect source language");
5716
+ }
5717
+ effectiveFromLang = detected;
5718
+ } else {
5719
+ effectiveFromLang = fromLang;
5720
+ }
5721
+ if (effectiveFromLang === toLang) {
5722
+ result = text;
5723
+ } else if (!isHTML) {
5724
+ config2 = config2 ?? getConfig();
5725
+ result = text.length > config2.maxSentenceLength ? await translateLongText(effectiveFromLang, toLang, text) : await translateSegment(effectiveFromLang, toLang, text, isHTML);
5726
+ } else {
5727
+ result = await translateSegment(effectiveFromLang, toLang, text, isHTML);
5728
+ }
5742
5729
  } else {
5743
- try {
5744
- const translated = await translateSegment(seg.language, toLang, seg.text, isHTML);
5745
- result += translated;
5746
- } catch (error2) {
5747
- error(`Failed to translate segment: ${error2}`);
5748
- result += seg.text;
5730
+ debug(`Detected ${segments.length} language segments`);
5731
+ result = "";
5732
+ let lastEnd = 0;
5733
+ for (const seg of segments) {
5734
+ if (seg.start > lastEnd) {
5735
+ result += text.substring(lastEnd, seg.start);
5736
+ }
5737
+ if (seg.language === toLang) {
5738
+ result += seg.text;
5739
+ } else {
5740
+ try {
5741
+ const translated = await translateSegment(seg.language, toLang, seg.text, isHTML);
5742
+ result += translated;
5743
+ } catch (error2) {
5744
+ error(`Failed to translate segment: ${error2}`);
5745
+ result += seg.text;
5746
+ }
5747
+ }
5748
+ lastEnd = seg.end;
5749
+ }
5750
+ if (lastEnd < text.length) {
5751
+ result += text.substring(lastEnd);
5749
5752
  }
5750
5753
  }
5751
- lastEnd = seg.end;
5752
5754
  }
5753
- if (lastEnd < text.length) {
5754
- result += text.substring(lastEnd);
5755
+ if (!toLang.startsWith("zh")) {
5756
+ return result;
5755
5757
  }
5756
- return formatChinesePunctuation(result, toLang, isHTML, shouldFullwidth);
5758
+ config2 = config2 ?? getConfig();
5759
+ return formatChinesePunctuation(result, toLang, isHTML, config2.fullwidthZhPunctuation);
5757
5760
  }
5758
5761
  async function translateLongText(fromLang, toLang, text) {
5759
5762
  debug(`Splitting long text (${text.length} chars) into sentences`);
@@ -5788,7 +5791,7 @@ function cleanupAllEngines() {
5788
5791
  engines.clear();
5789
5792
  info("All engines cleaned up successfully");
5790
5793
  }
5791
- var import_bergamot_translator, engines, loadingPromises, zhPunctTest, zhPunctGlobal;
5794
+ var import_bergamot_translator, engines, loadingPromises, zhCommaTest, zhCommaGlobal;
5792
5795
  var init_engine2 = __esm(() => {
5793
5796
  init_engine();
5794
5797
  init_factory();
@@ -5801,8 +5804,8 @@ var init_engine2 = __esm(() => {
5801
5804
  import_bergamot_translator = __toESM(require_bergamot_translator(), 1);
5802
5805
  engines = new Map;
5803
5806
  loadingPromises = new Map;
5804
- zhPunctTest = /[!-/:-@[-`{-~]/;
5805
- zhPunctGlobal = /[!-/:-@[-`{-~]/g;
5807
+ zhCommaTest = /,/;
5808
+ zhCommaGlobal = /,/g;
5806
5809
  });
5807
5810
 
5808
5811
  // src/services/index.ts
@@ -213930,7 +213933,7 @@ __export(exports_version, {
213930
213933
  function getVersion() {
213931
213934
  return VERSION;
213932
213935
  }
213933
- var VERSION = "4.0.31";
213936
+ var VERSION = "4.0.32";
213934
213937
 
213935
213938
  // src/server/index.ts
213936
213939
  init_config();
@@ -215732,7 +215735,7 @@ var swagger_default = {
215732
215735
  },
215733
215736
  info: {
215734
215737
  title: "MTranServer API",
215735
- version: "4.0.31",
215738
+ version: "4.0.32",
215736
215739
  description: "Translation server API",
215737
215740
  license: {
215738
215741
  name: "Apache-2.0"
@@ -1 +1 @@
1
- {"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../../src/services/engine.ts"],"names":[],"mappings":"AAkOA,wBAAsB,kBAAkB,CACtC,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,MAAM,GAAE,OAAe,GACtB,OAAO,CAAC,MAAM,CAAC,CA0EjB;AAkCD,wBAAgB,iBAAiB,SAahC"}
1
+ {"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../../src/services/engine.ts"],"names":[],"mappings":"AAiOA,wBAAsB,kBAAkB,CACtC,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,MAAM,GAAE,OAAe,GACtB,OAAO,CAAC,MAAM,CAAC,CA0EjB;AAkCD,wBAAgB,iBAAiB,SAahC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mtranserver",
3
- "version": "4.0.31",
3
+ "version": "4.0.32",
4
4
  "type": "module",
5
5
  "description": "Translation server",
6
6
  "main": "./dist/index.js",