diff --git a/src/class/Translate.mjs b/src/class/Translate.mjs index ba572665..40e157c9 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]] ?? source?.toLowerCase() ?? "auto"; + target = this.#LanguagesCode.Google[target] ?? this.#LanguagesCode.Google[target?.split?.(/[-_]/)?.[0]] ?? target.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]] ?? source?.toLowerCase() ?? "auto"; + target = this.#LanguagesCode.Google[target] ?? this.#LanguagesCode.Google[target?.split?.(/[-_]/)?.[0]] ?? target.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]] ?? source?.toLowerCase() ?? ""; + target = this.#LanguagesCode.Microsoft[target] ?? this.#LanguagesCode.Microsoft[target?.split?.(/[-_]/)?.[0]] ?? target.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]] ?? source?.toLowerCase() ?? ""; + target = this.#LanguagesCode.DeepL[target] ?? this.#LanguagesCode.DeepL[target?.split?.(/[-_]/)?.[0]] ?? target.toLowerCase(); const request = {}; let BaseURL = "https://api-free.deepl.com"; switch (api?.Version) { @@ -243,8 +243,8 @@ export default class Translate { async BaiduFanyi(text = [], source = this.Source, target = this.Target, api = this.API) { text = (Array.isArray(text)) ? text : [text]; - source = this.#LanguagesCode.Baidu[source] ?? this.#LanguagesCode.Baidu[source?.split?.(/[-_]/)?.[0]]; - target = this.#LanguagesCode.Baidu[target] ?? this.#LanguagesCode.Baidu[target?.split?.(/[-_]/)?.[0]]; + source = this.#LanguagesCode.Baidu[source] ?? this.#LanguagesCode.Baidu[source?.split?.(/[-_]/)?.[0]] ?? source?.toLowerCase() ?? "auto"; + target = this.#LanguagesCode.Baidu[target] ?? this.#LanguagesCode.Baidu[target?.split?.(/[-_]/)?.[0]] ?? target.toLowerCase(); const request = {}; // https://fanyi-api.baidu.com/doc/24 const BaseURL = "https://fanyi-api.baidu.com";