From d1658932679eefb91b65cb1c56e36216f1cb2e32 Mon Sep 17 00:00:00 2001 From: Virgil Clyne Date: Wed, 30 Oct 2024 09:02:08 +0800 Subject: [PATCH] feat(Translate): source & target Update Translate.mjs --- src/class/Translate.mjs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/class/Translate.mjs b/src/class/Translate.mjs index ba572665..fe31b913 100644 --- a/src/class/Translate.mjs +++ b/src/class/Translate.mjs @@ -4,7 +4,7 @@ import MD5 from 'crypto-js/md5.js'; export default class Translate { constructor(options = {}) { this.Name = "Translate"; - this.Version = "1.0.5"; + this.Version = "1.0.6"; log(`\n🟧 ${this.Name} v${this.Version}\n`); this.Source = "AUTO"; this.Target = "ZH"; @@ -44,8 +44,8 @@ export default class Translate { async Google(text = [], source = this.Source, target = this.Target) { text = (Array.isArray(text)) ? text : [text]; - source = this.#LanguagesCode.Google[source] ?? this.#LanguagesCode.Google[source?.split?.(/[-_]/)?.[0]]; - target = this.#LanguagesCode.Google[target] ?? this.#LanguagesCode.Google[target?.split?.(/[-_]/)?.[0]]; + source = this.#LanguagesCode.Google[source] ?? this.#LanguagesCode.Google[source?.split?.(/[-_]/)?.[0]] ?? "auto"; + target = this.#LanguagesCode.Google[target] ?? this.#LanguagesCode.Google[target?.split?.(/[-_]/)?.[0]] ?? target?.split?.(/[-_]/)?.[0]?.toLowerCase(); const BaseRequest = [ { // Google API @@ -101,8 +101,8 @@ export default class Translate { async GoogleCloud(text = [], source = this.Source, target = this.Target, api = this.API) { text = (Array.isArray(text)) ? text : [text]; - source = this.#LanguagesCode.Google[source] ?? this.#LanguagesCode.Google[source?.split?.(/[-_]/)?.[0]]; - target = this.#LanguagesCode.Google[target] ?? this.#LanguagesCode.Google[target?.split?.(/[-_]/)?.[0]]; + source = this.#LanguagesCode.Google[source] ?? this.#LanguagesCode.Google[source?.split?.(/[-_]/)?.[0]] ?? "auto"; + target = this.#LanguagesCode.Google[target] ?? this.#LanguagesCode.Google[target?.split?.(/[-_]/)?.[0]] ?? target?.split?.(/[-_]/)?.[0]?.toLowerCase(); const request = {}; const BaseURL = "https://translation.googleapis.com"; switch (api?.Version) { @@ -157,8 +157,8 @@ export default class Translate { async Microsoft(text = [], source = this.Source, target = this.Target, api = this.API) { text = (Array.isArray(text)) ? text : [text]; - source = this.#LanguagesCode.Microsoft[source] ?? this.#LanguagesCode.Microsoft[source?.split?.(/[-_]/)?.[0]]; - target = this.#LanguagesCode.Microsoft[target] ?? this.#LanguagesCode.Microsoft[target?.split?.(/[-_]/)?.[0]]; + source = this.#LanguagesCode.Microsoft[source] ?? this.#LanguagesCode.Microsoft[source?.split?.(/[-_]/)?.[0]] ?? ""; + target = this.#LanguagesCode.Microsoft[target] ?? this.#LanguagesCode.Microsoft[target?.split?.(/[-_]/)?.[0]] ?? target?.split?.(/[-_]/)?.[0]?.toLowerCase(); const request = {}; let BaseURL = "https://api.cognitive.microsofttranslator.com"; switch (api?.Version) { @@ -205,8 +205,8 @@ export default class Translate { async DeepL(text = [], source = this.Source, target = this.Target, api = this.API) { text = (Array.isArray(text)) ? text : [text]; - source = this.#LanguagesCode.DeepL[source] ?? this.#LanguagesCode.DeepL[source?.split?.(/[-_]/)?.[0]]; - target = this.#LanguagesCode.DeepL[target] ?? this.#LanguagesCode.DeepL[target?.split?.(/[-_]/)?.[0]]; + source = this.#LanguagesCode.DeepL[source] ?? this.#LanguagesCode.DeepL[source?.split?.(/[-_]/)?.[0]] ?? ""; + target = this.#LanguagesCode.DeepL[target] ?? this.#LanguagesCode.DeepL[target?.split?.(/[-_]/)?.[0]] ?? target?.split?.(/[-_]/)?.[0]?.toLowerCase(); const request = {}; let BaseURL = "https://api-free.deepl.com"; switch (api?.Version) {