@yxw007/translate 0.0.3 → 0.0.5

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.5 Copyright (c) 2024 Potter<aa4790139@gmail.com> and contributors
2
2
  (function (global, factory) {
3
3
  typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
4
4
  typeof define === 'function' && define.amd ? define(['exports'], factory) :
@@ -10,7 +10,7 @@
10
10
  return {
11
11
  name: "google",
12
12
  async translate(text, opts) {
13
- const { from, to } = opts;
13
+ const { from = "auto", to } = opts;
14
14
  if (!Array.isArray(text)) {
15
15
  text = [text];
16
16
  }
@@ -44,7 +44,7 @@
44
44
  name: "azure",
45
45
  async translate(text, opts) {
46
46
  const { from, to } = opts;
47
- const url = `${base}&from=${from}&to=${to}`;
47
+ const url = `${base}&to=${to}${from && from !== "auto" ? `&from=${from}` : ""}`;
48
48
  if (!Array.isArray(text)) {
49
49
  text = [text];
50
50
  }
@@ -4007,7 +4007,7 @@ ${toHex(hashedRequest)}`;
4007
4007
 
4008
4008
  var name = "@aws-sdk/client-translate";
4009
4009
  var description = "AWS SDK for JavaScript Translate Client for Node.js, Browser and React Native";
4010
- var version = "3.645.0";
4010
+ var version = "3.649.0";
4011
4011
  var scripts = {
4012
4012
  build: "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types'",
4013
4013
  "build:cjs": "node ../../scripts/compilation/inline client-translate",
@@ -4026,43 +4026,43 @@ ${toHex(hashedRequest)}`;
4026
4026
  var dependencies = {
4027
4027
  "@aws-crypto/sha256-browser": "5.2.0",
4028
4028
  "@aws-crypto/sha256-js": "5.2.0",
4029
- "@aws-sdk/client-sso-oidc": "3.645.0",
4030
- "@aws-sdk/client-sts": "3.645.0",
4031
- "@aws-sdk/core": "3.635.0",
4032
- "@aws-sdk/credential-provider-node": "3.645.0",
4033
- "@aws-sdk/middleware-host-header": "3.620.0",
4034
- "@aws-sdk/middleware-logger": "3.609.0",
4035
- "@aws-sdk/middleware-recursion-detection": "3.620.0",
4036
- "@aws-sdk/middleware-user-agent": "3.645.0",
4037
- "@aws-sdk/region-config-resolver": "3.614.0",
4038
- "@aws-sdk/types": "3.609.0",
4039
- "@aws-sdk/util-endpoints": "3.645.0",
4040
- "@aws-sdk/util-user-agent-browser": "3.609.0",
4041
- "@aws-sdk/util-user-agent-node": "3.614.0",
4042
- "@smithy/config-resolver": "^3.0.5",
4043
- "@smithy/core": "^2.4.0",
4044
- "@smithy/fetch-http-handler": "^3.2.4",
4045
- "@smithy/hash-node": "^3.0.3",
4046
- "@smithy/invalid-dependency": "^3.0.3",
4047
- "@smithy/middleware-content-length": "^3.0.5",
4048
- "@smithy/middleware-endpoint": "^3.1.0",
4049
- "@smithy/middleware-retry": "^3.0.15",
4050
- "@smithy/middleware-serde": "^3.0.3",
4051
- "@smithy/middleware-stack": "^3.0.3",
4052
- "@smithy/node-config-provider": "^3.1.4",
4053
- "@smithy/node-http-handler": "^3.1.4",
4054
- "@smithy/protocol-http": "^4.1.0",
4055
- "@smithy/smithy-client": "^3.2.0",
4056
- "@smithy/types": "^3.3.0",
4057
- "@smithy/url-parser": "^3.0.3",
4029
+ "@aws-sdk/client-sso-oidc": "3.649.0",
4030
+ "@aws-sdk/client-sts": "3.649.0",
4031
+ "@aws-sdk/core": "3.649.0",
4032
+ "@aws-sdk/credential-provider-node": "3.649.0",
4033
+ "@aws-sdk/middleware-host-header": "3.649.0",
4034
+ "@aws-sdk/middleware-logger": "3.649.0",
4035
+ "@aws-sdk/middleware-recursion-detection": "3.649.0",
4036
+ "@aws-sdk/middleware-user-agent": "3.649.0",
4037
+ "@aws-sdk/region-config-resolver": "3.649.0",
4038
+ "@aws-sdk/types": "3.649.0",
4039
+ "@aws-sdk/util-endpoints": "3.649.0",
4040
+ "@aws-sdk/util-user-agent-browser": "3.649.0",
4041
+ "@aws-sdk/util-user-agent-node": "3.649.0",
4042
+ "@smithy/config-resolver": "^3.0.6",
4043
+ "@smithy/core": "^2.4.1",
4044
+ "@smithy/fetch-http-handler": "^3.2.5",
4045
+ "@smithy/hash-node": "^3.0.4",
4046
+ "@smithy/invalid-dependency": "^3.0.4",
4047
+ "@smithy/middleware-content-length": "^3.0.6",
4048
+ "@smithy/middleware-endpoint": "^3.1.1",
4049
+ "@smithy/middleware-retry": "^3.0.16",
4050
+ "@smithy/middleware-serde": "^3.0.4",
4051
+ "@smithy/middleware-stack": "^3.0.4",
4052
+ "@smithy/node-config-provider": "^3.1.5",
4053
+ "@smithy/node-http-handler": "^3.2.0",
4054
+ "@smithy/protocol-http": "^4.1.1",
4055
+ "@smithy/smithy-client": "^3.3.0",
4056
+ "@smithy/types": "^3.4.0",
4057
+ "@smithy/url-parser": "^3.0.4",
4058
4058
  "@smithy/util-base64": "^3.0.0",
4059
4059
  "@smithy/util-body-length-browser": "^3.0.0",
4060
4060
  "@smithy/util-body-length-node": "^3.0.0",
4061
- "@smithy/util-defaults-mode-browser": "^3.0.15",
4062
- "@smithy/util-defaults-mode-node": "^3.0.15",
4063
- "@smithy/util-endpoints": "^2.0.5",
4064
- "@smithy/util-middleware": "^3.0.3",
4065
- "@smithy/util-retry": "^3.0.3",
4061
+ "@smithy/util-defaults-mode-browser": "^3.0.16",
4062
+ "@smithy/util-defaults-mode-node": "^3.0.16",
4063
+ "@smithy/util-endpoints": "^2.1.0",
4064
+ "@smithy/util-middleware": "^3.0.4",
4065
+ "@smithy/util-retry": "^3.0.4",
4066
4066
  "@smithy/util-utf8": "^3.0.0",
4067
4067
  tslib: "^2.6.2",
4068
4068
  uuid: "^9.0.1"
@@ -5392,7 +5392,7 @@ ${toHex(hashedRequest)}`;
5392
5392
  return {
5393
5393
  name: "amazon",
5394
5394
  async translate(text, opts) {
5395
- const { from, to } = opts;
5395
+ const { from = "auto", to } = opts;
5396
5396
  const translateClient = new TranslateClient({ region: region, credentials: { accessKeyId, secretAccessKey } });
5397
5397
  if (!Array.isArray(text)) {
5398
5398
  text = [text];
@@ -6511,7 +6511,7 @@ ${toHex(hashedRequest)}`;
6511
6511
  return {
6512
6512
  name: "baidu",
6513
6513
  async translate(text, opts) {
6514
- const { to, from, domain = "it" } = opts;
6514
+ const { to, from = "auto", domain = "it" } = opts;
6515
6515
  if (!Array.isArray(text)) {
6516
6516
  text = [text];
6517
6517
  }
@@ -6742,13 +6742,255 @@ ${toHex(hashedRequest)}`;
6742
6742
  zul: "zu",
6743
6743
  };
6744
6744
 
6745
- const isoKeys = Object.values(iso).sort();
6746
- function language(name) {
6745
+ var languageNames = {
6746
+ afar: "aa",
6747
+ abkhazian: "ab",
6748
+ afrikaans: "af",
6749
+ akan: "ak",
6750
+ albanian: "sq",
6751
+ amharic: "am",
6752
+ arabic: "ar",
6753
+ aragonese: "an",
6754
+ armenian: "hy",
6755
+ assamese: "as",
6756
+ avaric: "av",
6757
+ avestan: "ae",
6758
+ aymara: "ay",
6759
+ azerbaijani: "az",
6760
+ bashkir: "ba",
6761
+ bambara: "bm",
6762
+ basque: "eu",
6763
+ belarusian: "be",
6764
+ bengali: "bn",
6765
+ "bihari languages": "bh",
6766
+ bislama: "bi",
6767
+ tibetan: "bo",
6768
+ bosnian: "bs",
6769
+ breton: "br",
6770
+ bulgarian: "bg",
6771
+ burmese: "my",
6772
+ catalan: "ca",
6773
+ valencian: "ca",
6774
+ czech: "cs",
6775
+ chamorro: "ch",
6776
+ chechen: "ce",
6777
+ chinese: "zh",
6778
+ "church slavic": "cu",
6779
+ "old slavonic": "cu",
6780
+ "church slavonic": "cu",
6781
+ "old bulgarian": "cu",
6782
+ "old church slavonic": "cu",
6783
+ chuvash: "cv",
6784
+ cornish: "kw",
6785
+ corsican: "co",
6786
+ cree: "cr",
6787
+ welsh: "cy",
6788
+ danish: "da",
6789
+ german: "de",
6790
+ divehi: "dv",
6791
+ dhivehi: "dv",
6792
+ maldivian: "dv",
6793
+ dutch: "nl",
6794
+ flemish: "nl",
6795
+ dzongkha: "dz",
6796
+ greek: "el",
6797
+ english: "en",
6798
+ esperanto: "eo",
6799
+ estonian: "et",
6800
+ ewe: "ee",
6801
+ faroese: "fo",
6802
+ persian: "fa",
6803
+ fijian: "fj",
6804
+ finnish: "fi",
6805
+ french: "fr",
6806
+ "western frisian": "fy",
6807
+ fulah: "ff",
6808
+ georgian: "ka",
6809
+ gaelic: "gd",
6810
+ "scottish gaelic": "gd",
6811
+ irish: "ga",
6812
+ galician: "gl",
6813
+ manx: "gv",
6814
+ guarani: "gn",
6815
+ gujarati: "gu",
6816
+ haitian: "ht",
6817
+ "haitian creole": "ht",
6818
+ hausa: "ha",
6819
+ hebrew: "he",
6820
+ herero: "hz",
6821
+ hindi: "hi",
6822
+ "hiri motu": "ho",
6823
+ croatian: "hr",
6824
+ hungarian: "hu",
6825
+ igbo: "ig",
6826
+ icelandic: "is",
6827
+ ido: "io",
6828
+ "sichuan yi": "ii",
6829
+ nuosu: "ii",
6830
+ inuktitut: "iu",
6831
+ interlingue: "ie",
6832
+ occidental: "ie",
6833
+ interlingua: "ia",
6834
+ indonesian: "id",
6835
+ inupiaq: "ik",
6836
+ italian: "it",
6837
+ javanese: "jv",
6838
+ japanese: "ja",
6839
+ kalaallisut: "kl",
6840
+ greenlandic: "kl",
6841
+ kannada: "kn",
6842
+ kashmiri: "ks",
6843
+ kanuri: "kr",
6844
+ kazakh: "kk",
6845
+ "central khmer": "km",
6846
+ kikuyu: "ki",
6847
+ gikuyu: "ki",
6848
+ kinyarwanda: "rw",
6849
+ kirghiz: "ky",
6850
+ kyrgyz: "ky",
6851
+ komi: "kv",
6852
+ kongo: "kg",
6853
+ korean: "ko",
6854
+ kuanyama: "kj",
6855
+ kwanyama: "kj",
6856
+ kurdish: "ku",
6857
+ lao: "lo",
6858
+ latin: "la",
6859
+ latvian: "lv",
6860
+ limburgan: "li",
6861
+ limburger: "li",
6862
+ limburgish: "li",
6863
+ lingala: "ln",
6864
+ lithuanian: "lt",
6865
+ luxembourgish: "lb",
6866
+ letzeburgesch: "lb",
6867
+ "luba-katanga": "lu",
6868
+ ganda: "lg",
6869
+ macedonian: "mk",
6870
+ marshallese: "mh",
6871
+ malayalam: "ml",
6872
+ maori: "mi",
6873
+ marathi: "mr",
6874
+ malay: "ms",
6875
+ malagasy: "mg",
6876
+ maltese: "mt",
6877
+ mongolian: "mn",
6878
+ nauru: "na",
6879
+ navajo: "nv",
6880
+ navaho: "nv",
6881
+ "ndebele, south": "nr",
6882
+ "south ndebele": "nr",
6883
+ "ndebele, north": "nd",
6884
+ "north ndebele": "nd",
6885
+ ndonga: "ng",
6886
+ nepali: "ne",
6887
+ "norwegian nynorsk": "nn",
6888
+ "nynorsk, norwegian": "nn",
6889
+ "norwegian bokmål": "nb",
6890
+ "bokmål, norwegian": "nb",
6891
+ norwegian: "no",
6892
+ chichewa: "ny",
6893
+ chewa: "ny",
6894
+ nyanja: "ny",
6895
+ occitan: "oc",
6896
+ ojibwa: "oj",
6897
+ oriya: "or",
6898
+ oromo: "om",
6899
+ ossetian: "os",
6900
+ ossetic: "os",
6901
+ panjabi: "pa",
6902
+ punjabi: "pa",
6903
+ pali: "pi",
6904
+ polish: "pl",
6905
+ portuguese: "pt",
6906
+ pushto: "ps",
6907
+ pashto: "ps",
6908
+ quechua: "qu",
6909
+ romansh: "rm",
6910
+ romanian: "ro",
6911
+ moldavian: "ro",
6912
+ moldovan: "ro",
6913
+ rundi: "rn",
6914
+ russian: "ru",
6915
+ sango: "sg",
6916
+ sanskrit: "sa",
6917
+ sinhala: "si",
6918
+ sinhalese: "si",
6919
+ slovak: "sk",
6920
+ slovenian: "sl",
6921
+ "northern sami": "se",
6922
+ samoan: "sm",
6923
+ shona: "sn",
6924
+ sindhi: "sd",
6925
+ somali: "so",
6926
+ "sotho, southern": "st",
6927
+ spanish: "es",
6928
+ castilian: "es",
6929
+ sardinian: "sc",
6930
+ serbian: "sr",
6931
+ swati: "ss",
6932
+ sundanese: "su",
6933
+ swahili: "sw",
6934
+ swedish: "sv",
6935
+ tahitian: "ty",
6936
+ tamil: "ta",
6937
+ tatar: "tt",
6938
+ telugu: "te",
6939
+ tajik: "tg",
6940
+ tagalog: "tl",
6941
+ thai: "th",
6942
+ tigrinya: "ti",
6943
+ tonga: "to",
6944
+ tswana: "tn",
6945
+ tsonga: "ts",
6946
+ turkmen: "tk",
6947
+ turkish: "tr",
6948
+ twi: "tw",
6949
+ uighur: "ug",
6950
+ uyghur: "ug",
6951
+ ukrainian: "uk",
6952
+ urdu: "ur",
6953
+ uzbek: "uz",
6954
+ venda: "ve",
6955
+ vietnamese: "vi",
6956
+ volapük: "vo",
6957
+ walloon: "wa",
6958
+ wolof: "wo",
6959
+ xhosa: "xh",
6960
+ yiddish: "yi",
6961
+ yoruba: "yo",
6962
+ zhuang: "za",
6963
+ chuang: "za",
6964
+ zulu: "zu",
6965
+ };
6966
+
6967
+ const nameKeys = Object.keys(languageNames).sort();
6968
+ const isoKeys = Object.keys(iso).sort();
6969
+ const iosValues = Object.values(iso);
6970
+ function isValidLanguage(name) {
6971
+ if (!name) {
6972
+ return false;
6973
+ }
6974
+ if (name === "auto") {
6975
+ return true;
6976
+ }
6747
6977
  if (name.length > 100) {
6748
6978
  throw new Error(`The "language" is too long at ${name.length} characters`);
6749
6979
  }
6750
- if (!isoKeys.includes(name)) {
6751
- throw new Error(`The language "${name}" is not part of the ISO 639-1`);
6980
+ return isoKeys.includes(name) || nameKeys.includes(name) || iosValues.includes(name);
6981
+ }
6982
+ function getISO(name) {
6983
+ if (name === "auto") {
6984
+ return name;
6985
+ }
6986
+ if (nameKeys.includes(name)) {
6987
+ return languageNames[name];
6988
+ }
6989
+ if (isoKeys.includes(name)) {
6990
+ return iso[name];
6991
+ }
6992
+ if (iosValues.includes(name)) {
6993
+ return name;
6752
6994
  }
6753
6995
  return name;
6754
6996
  }
@@ -6845,17 +7087,20 @@ ${toHex(hashedRequest)}`;
6845
7087
  this.engines.set(engine.name, engine);
6846
7088
  }
6847
7089
  translate(text, options) {
6848
- const { from, to, engine = "google", cache_time = 60 * 1000 } = options;
7090
+ const { engine = "google", cache_time = 60 * 1000 } = options;
7091
+ let { from = "auto", to } = options;
7092
+ from = options.from = getISO(from);
7093
+ to = options.to = getISO(to);
6849
7094
  //1. Check if engine exists
6850
7095
  if (!this.engines.has(engine)) {
6851
7096
  throw new Error(`Engine ${engine} not found`);
6852
7097
  }
6853
7098
  //2. Check if language exists
6854
- if (!language(from)) {
6855
- throw new Error(`Language ${from} not found`);
7099
+ if (!isValidLanguage(to)) {
7100
+ throw new Error(`The language "${to}" is not part of the ISO 639-1 or is not part of the language names`);
6856
7101
  }
6857
- if (!language(to)) {
6858
- throw new Error(`Language ${to} not found`);
7102
+ if (!isValidLanguage(from)) {
7103
+ throw new Error(`The language "${from}" is not part of the ISO 639-1 or is not part of the language names`);
6859
7104
  }
6860
7105
  const key = `${from}:${to}:${engine}:${text}`;
6861
7106
  //3. If the cache is matched, the cache is used directly
@@ -6876,11 +7121,14 @@ ${toHex(hashedRequest)}`;
6876
7121
  var index = {
6877
7122
  engines,
6878
7123
  translator,
7124
+ Cache,
7125
+ languageNames,
6879
7126
  };
6880
7127
 
6881
7128
  exports.Cache = Cache;
6882
7129
  exports.default = index;
6883
7130
  exports.engines = engines;
7131
+ exports.languageNames = languageNames;
6884
7132
  exports.translator = translator;
6885
7133
 
6886
7134
  Object.defineProperty(exports, '__esModule', { value: true });