Skip to content

Commit

Permalink
feat(Translate): source & target
Browse files Browse the repository at this point in the history
Update Translate.mjs
  • Loading branch information
VirgilClyne committed Oct 30, 2024
1 parent 806f682 commit 50e130d
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/class/Translate.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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();
target = this.#LanguagesCode.Google[target] ?? this.#LanguagesCode.Google[target?.split?.(/[-_]/)?.[0]] ?? target.toLowerCase();
const BaseRequest = [
{
// Google API
Expand Down Expand Up @@ -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();
target = this.#LanguagesCode.Google[target] ?? this.#LanguagesCode.Google[target?.split?.(/[-_]/)?.[0]] ?? target.toLowerCase();
const request = {};
const BaseURL = "https://translation.googleapis.com";
switch (api?.Version) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
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";
Expand Down

0 comments on commit 50e130d

Please sign in to comment.