@yxw007/translate 0.0.3 → 0.0.4

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.
@@ -1,4 +1,4 @@
1
- // translate v0.0.3 Copyright (c) 2024 Potter<aa4790139@gmail.com> and contributors
1
+ // translate v0.0.4 Copyright (c) 2024 Potter<aa4790139@gmail.com> and contributors
2
2
  'use strict';
3
3
 
4
4
  Object.defineProperty(exports, '__esModule', { value: true });
@@ -8,7 +8,7 @@ function google(options) {
8
8
  return {
9
9
  name: "google",
10
10
  async translate(text, opts) {
11
- const { from, to } = opts;
11
+ const { from = "auto", to } = opts;
12
12
  if (!Array.isArray(text)) {
13
13
  text = [text];
14
14
  }
@@ -42,7 +42,7 @@ function azure(options) {
42
42
  name: "azure",
43
43
  async translate(text, opts) {
44
44
  const { from, to } = opts;
45
- const url = `${base}&from=${from}&to=${to}`;
45
+ const url = `${base}&to=${to}${from ? `&from=${from}` : ""}`;
46
46
  if (!Array.isArray(text)) {
47
47
  text = [text];
48
48
  }
@@ -5390,7 +5390,7 @@ function amazon(options) {
5390
5390
  return {
5391
5391
  name: "amazon",
5392
5392
  async translate(text, opts) {
5393
- const { from, to } = opts;
5393
+ const { from = "auto", to } = opts;
5394
5394
  const translateClient = new TranslateClient({ region: region, credentials: { accessKeyId, secretAccessKey } });
5395
5395
  if (!Array.isArray(text)) {
5396
5396
  text = [text];
@@ -6509,7 +6509,7 @@ function baidu(options) {
6509
6509
  return {
6510
6510
  name: "baidu",
6511
6511
  async translate(text, opts) {
6512
- const { to, from, domain = "it" } = opts;
6512
+ const { to, from = "auto", domain = "it" } = opts;
6513
6513
  if (!Array.isArray(text)) {
6514
6514
  text = [text];
6515
6515
  }
@@ -6849,9 +6849,6 @@ class Translator {
6849
6849
  throw new Error(`Engine ${engine} not found`);
6850
6850
  }
6851
6851
  //2. Check if language exists
6852
- if (!language(from)) {
6853
- throw new Error(`Language ${from} not found`);
6854
- }
6855
6852
  if (!language(to)) {
6856
6853
  throw new Error(`Language ${to} not found`);
6857
6854
  }