generaltranslation 2.0.45 → 2.0.47

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
@@ -178,13 +178,32 @@ console.log(result.translation); // { "type": "div", "props": { "children": "Hol
178
178
 
179
179
  #### Parameters
180
180
 
181
- - `content` (any): The React children content to be translated.
182
- - `targetLanguage` (string): The target language for the translation.
183
- - `metadata` (object): Additional metadata for the translation process.
181
+ - `requests` (Request[]): An array of request objects. Each request can be of type `translate`, `intl`, or `react`.
182
+
183
+ - **Translate Request**:
184
+ - `type`: `'translate'`
185
+ - `data`: An object containing:
186
+ - `content` (string): The string content to be translated.
187
+ - `targetLanguage` (string): The target language for the translation.
188
+ - `metadata` (Record<string, any>): Additional metadata for the translation process.
189
+
190
+ - **Intl Request**:
191
+ - `type`: `'intl'`
192
+ - `data`: An object containing:
193
+ - `content` (string): The string content to be translated.
194
+ - `targetLanguage` (string): The target language for the translation.
195
+ - `metadata` (Record<string, any>): Additional metadata for the translation process.
196
+
197
+ - **React Request**:
198
+ - `type`: `'intl'`
199
+ - `data`: An object containing:
200
+ - `children` (object | string): The React children content to be translated.
201
+ - `targetLanguage` (string): The target language for the translation.
202
+ - `metadata` (Record<string, any>): Additional metadata for the translation process.
184
203
 
185
204
  #### Returns
186
205
 
187
- - A promise that resolves to an object containing the translated content and optional error information.
206
+ - A promise that resolves to an object containing the translated content, optional error information, and dictionary information for react and intl requests.
188
207
 
189
208
  #### `bundleTranslation(requests: any[]): Promise<Array<any | null>>`
190
209
 
@@ -193,13 +212,13 @@ Bundles multiple requests and sends them to the server.
193
212
  ```javascript
194
213
  const requests = [
195
214
  {
196
- type: "intl"
215
+ type: "translate"
197
216
  data: {
198
217
  content: 'Hello', targetLanguage: 'es'
199
218
  }
200
219
  }
201
220
  {
202
- type: "intl"
221
+ type: "translate"
203
222
  data: {
204
223
  content: 'Hello', targetLanguage: 'de'
205
224
  }
@@ -207,7 +226,7 @@ const requests = [
207
226
 
208
227
  ];
209
228
  const results = await gt.bundleTranslation(requests);
210
- console.log(results); // ['Hola', 'Hallo']
229
+ console.log(results); // [{ translation: "Hola", language: "es" }, { translation: "Hallo", language: "de" }]
211
230
  ```
212
231
 
213
232
  #### Parameters
@@ -218,6 +237,50 @@ console.log(results); // ['Hola', 'Hallo']
218
237
 
219
238
  - A promise that resolves to an array of processed results.
220
239
 
240
+ ### updateRemoteDictionary(updates)
241
+
242
+ Pushes updates to a remotely cached translation dictionary.
243
+
244
+ #### Parameters
245
+
246
+ - `updates` (Update[]): An array of update objects. Each update can be of type `react` or `intl`.
247
+
248
+ - **React Update**:
249
+ - `type`: `'react'`
250
+ - `data`: An object containing:
251
+ - `children` (object | string): The React children content to be translated.
252
+ - `targetLanguage` (string, optional): The target language for the translation.
253
+ - `metadata` (Record<string, any>): Additional metadata for the translation process.
254
+
255
+ - **Intl Update**:
256
+ - `type`: `'intl'`
257
+ - `data`: An object containing:
258
+ - `content` (string): The string content to be translated.
259
+ - `targetLanguage` (string, optional): The target language for the translation.
260
+ - `metadata` (Record<string, any>): Additional metadata for the translation process.
261
+
262
+ #### Returns
263
+
264
+ - A promise that resolves to a boolean indicating success (`true`) or failure (`false`).
265
+
266
+ #### Example
267
+
268
+ ```js
269
+ import { updateRemoteDictionary } from 'generaltranslation';
270
+ const updates = [
271
+ {
272
+ type: 'react',
273
+ data: {
274
+ children: { type: 'div', props: { children: 'Hello, world' } },
275
+ targetLanguage: 'es',
276
+ metadata: { id: 'greeting' }
277
+ }
278
+ }
279
+ ];
280
+ const success = await updateRemoteDictionary(updates);
281
+ console.log(success); // true or false
282
+ ```
283
+
221
284
  ## Utility Functions
222
285
 
223
286
  ### getLanguageDirection
package/dist/index.d.ts CHANGED
@@ -85,7 +85,7 @@ declare class GT {
85
85
  * @param updates - Array of updates with optional targetLanguage.
86
86
  * @returns A promise that resolves to a boolean indicating success or failure.
87
87
  */
88
- updateRemoteDictionary(updates: Update[]): Promise<boolean>;
88
+ updateRemoteDictionary(updates: Update[]): Promise<string[]>;
89
89
  }
90
90
  export default GT;
91
91
  /**
@@ -13,7 +13,7 @@ export type Request = {
13
13
  metadata: Record<string, any>;
14
14
  };
15
15
  } | {
16
- type: 'intl';
16
+ type: 'react';
17
17
  data: {
18
18
  children: object | string;
19
19
  targetLanguage: string;
@@ -2,14 +2,14 @@ export type Update = {
2
2
  type: 'react';
3
3
  data: {
4
4
  children: object | string;
5
- targetLanguage?: string;
5
+ targetLanguages?: string[];
6
6
  metadata: Record<string, any>;
7
7
  };
8
8
  } | {
9
9
  type: 'intl';
10
10
  data: {
11
11
  content: string;
12
- targetLanguage?: string;
12
+ targetLanguages?: string[];
13
13
  metadata: Record<string, any>;
14
14
  };
15
15
  };
@@ -32,15 +32,15 @@ function _updateRemoteDictionary(gt, updates) {
32
32
  throw new Error(`${response.status}: ${yield response.text()}`);
33
33
  }
34
34
  const result = yield response.json();
35
- return result.success;
35
+ return result.languages;
36
36
  }
37
37
  catch (error) {
38
38
  if (error instanceof Error && error.name === 'AbortError') {
39
39
  console.error('Request timed out');
40
- return false;
40
+ return [];
41
41
  }
42
42
  console.error(error);
43
- return false;
43
+ return [];
44
44
  }
45
45
  });
46
46
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "generaltranslation",
3
- "version": "2.0.45",
3
+ "version": "2.0.47",
4
4
  "description": "A language toolkit for AI developers",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",