generaltranslation 1.2.11 → 1.2.13

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.
package/README.md CHANGED
@@ -123,6 +123,15 @@ const translatedPrompt = await gt.translate({ text: 'Tell me a story' }, 'es');
123
123
  Translates multiple items of content into the language represented by an ISO-639 language code. Caches by default. Just wrap `translateMany` around an array of what you want to translate and specify a language. For example:
124
124
 
125
125
  ```
126
- const contentArray = ['You say goodbye', 'And I say hello'];
127
- const translationArray = await gt.translateMany(contentArray, 'es') // returns an array
126
+ const requests = [
127
+ {
128
+ content: "You say goodbye",
129
+ language: "es"
130
+ },
131
+ {
132
+ content: "And I say hello.",
133
+ language: "de"
134
+ }
135
+ ];
136
+ const translationArray = await gt.translateMany(requests) // returns an array
128
137
  ```
package/index.js CHANGED
@@ -57,9 +57,10 @@ class GT {
57
57
  }
58
58
 
59
59
  // String translation, of an array of strings
60
- async translateMany(contentArray, language, { ... options }) {
60
+ // requestArray looks like { content: '', language: '' }
61
+ async translateMany(requestArray) {
61
62
  return await _translateMany({
62
- contentArray: contentArray, language: language, config: this, ...options,
63
+ requestArray, config: this
63
64
  });
64
65
  }
65
66
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "generaltranslation",
3
- "version": "1.2.11",
3
+ "version": "1.2.13",
4
4
  "description": "A language toolkit for AI developers",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -119,7 +119,7 @@ const constructAll = (contentArray) => {
119
119
  // Get a translation of multiple strings via General Translation API
120
120
  // Returns array of strings
121
121
  const _translateMany = async ({
122
- contentArray, language, config, ...options
122
+ requestArray, config
123
123
  }) => {
124
124
 
125
125
  const apiKey = config?.apiKey;
@@ -127,17 +127,12 @@ const _translateMany = async ({
127
127
  throw new Error('Missing API Key!')
128
128
  };
129
129
 
130
- const defaultLanguage = config?.defaultLanguage;
131
- if (language === defaultLanguage) {
132
- return constructAll(contentArray);
133
- };
134
-
135
- const processedArray = [];
130
+ const processedRequests = [];
136
131
  const untranslatedArray = [];
137
132
 
138
- for (const item of contentArray) {
139
- const { processed, untranslated } = _processContent({ content: item });
140
- processedArray.push(processed);
133
+ for (const item of requestArray) {
134
+ const { processed, untranslated } = _processContent({ content: item?.content });
135
+ processedRequests.push({ content: processed, language: item.language, options: { ...item.options } });
141
136
  untranslatedArray.push(untranslated);
142
137
  };
143
138
 
@@ -149,9 +144,8 @@ const _translateMany = async ({
149
144
  'gtx-api-key': apiKey,
150
145
  },
151
146
  body: JSON.stringify({
152
- content: processedArray,
147
+ processedRequests: processedRequests,
153
148
  targetLanguage: language,
154
- defaultLanguage: defaultLanguage,
155
149
  options: { ...options }
156
150
  })
157
151
  })
@@ -171,7 +165,7 @@ const _translateMany = async ({
171
165
  }
172
166
  } catch (error) {
173
167
  console.error(error)
174
- return constructAll(contentArray);
168
+ return constructAll(requestArray.map(item => item.content));
175
169
  }
176
170
 
177
171
  }