generaltranslation 2.0.44 → 2.0.46

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "generaltranslation",
3
- "version": "2.0.44",
3
+ "version": "2.0.46",
4
4
  "description": "A language toolkit for AI developers",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",