@translated/lara 1.6.5 β 1.6.6
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 +360 -2
- package/lib/net/browser-client.js +6 -3
- package/lib/net/index.js +1 -1
- package/lib/net/node-client.js +6 -3
- package/lib/sdk-version.d.ts +1 -1
- package/lib/sdk-version.js +1 -1
- package/lib/translator/models.d.ts +9 -3
- package/lib/translator/translator.d.ts +1 -1
- package/lib/translator/translator.js +10 -5
- package/lib/utils/toSnakeCase.d.ts +2 -0
- package/lib/utils/toSnakeCase.js +18 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,7 +1,365 @@
|
|
|
1
|
-
# Lara Node.js
|
|
1
|
+
# Lara Node.js SDK
|
|
2
|
+
|
|
3
|
+
[](https://nodejs.org)
|
|
4
|
+
[](LICENSE)
|
|
2
5
|
|
|
3
6
|
This SDK empowers you to build your own branded translation AI leveraging our translation fine-tuned language model.
|
|
4
7
|
|
|
5
8
|
All major translation features are accessible, making it easy to integrate and customize for your needs.
|
|
6
9
|
|
|
7
|
-
|
|
10
|
+
## π **Features:**
|
|
11
|
+
- **Text Translation**: Single strings, multiple strings, and complex text blocks
|
|
12
|
+
- **Document Translation**: Word, PDF, and other document formats with status monitoring
|
|
13
|
+
- **Translation Memory**: Store and reuse translations for consistency
|
|
14
|
+
- **Glossaries**: Enforce terminology standards across translations
|
|
15
|
+
- **Language Detection**: Automatic source language identification
|
|
16
|
+
- **Advanced Options**: Translation instructions and more
|
|
17
|
+
|
|
18
|
+
## π Documentation
|
|
19
|
+
|
|
20
|
+
Lara's SDK full documentation is available at [https://developers.laratranslate.com/](https://developers.laratranslate.com/)
|
|
21
|
+
|
|
22
|
+
## π Quick Start
|
|
23
|
+
|
|
24
|
+
### Installation
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
npm install @translated/lara
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### Basic Usage
|
|
31
|
+
|
|
32
|
+
```javascript
|
|
33
|
+
const { Credentials, Translator } = require('@translated/lara');
|
|
34
|
+
|
|
35
|
+
// Set your credentials using environment variables (recommended)
|
|
36
|
+
const credentials = new Credentials(
|
|
37
|
+
process.env.LARA_ACCESS_KEY_ID,
|
|
38
|
+
process.env.LARA_ACCESS_KEY_SECRET
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
// Create translator instance
|
|
42
|
+
const lara = new Translator(credentials);
|
|
43
|
+
|
|
44
|
+
// Simple text translation
|
|
45
|
+
async function translateText() {
|
|
46
|
+
try {
|
|
47
|
+
const result = await lara.translate("Hello, world!", "en-US", "fr-FR");
|
|
48
|
+
console.log("Translation: " + result.translation);
|
|
49
|
+
// Output: Translation: Bonjour, le monde !
|
|
50
|
+
} catch (error) {
|
|
51
|
+
console.error("Translation error:", error.message);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
translateText();
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## π Examples
|
|
59
|
+
|
|
60
|
+
The `examples/` directory contains comprehensive examples for all SDK features.
|
|
61
|
+
|
|
62
|
+
**All examples use environment variables for credentials, so set them first:**
|
|
63
|
+
```bash
|
|
64
|
+
export LARA_ACCESS_KEY_ID="your-access-key-id"
|
|
65
|
+
export LARA_ACCESS_KEY_SECRET="your-access-key-secret"
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Text Translation
|
|
69
|
+
- **[text_translation.js](examples/text_translation.js)** - Complete text translation examples
|
|
70
|
+
- Single string translation
|
|
71
|
+
- Multiple strings translation
|
|
72
|
+
- Translation with instructions
|
|
73
|
+
- TextBlocks translation (mixed translatable/non-translatable content)
|
|
74
|
+
- Auto-detect source language
|
|
75
|
+
- Advanced translation options
|
|
76
|
+
- Get available languages
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
cd examples
|
|
80
|
+
node text_translation.js
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### Document Translation
|
|
84
|
+
- **[document_translation.js](examples/document_translation.js)** - Document translation examples
|
|
85
|
+
- Basic document translation
|
|
86
|
+
- Advanced options with memories and glossaries
|
|
87
|
+
- Step-by-step translation with status monitoring
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
cd examples
|
|
91
|
+
node document_translation.js
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### Translation Memory Management
|
|
95
|
+
- **[memories_management.js](examples/memories_management.js)** - Memory management examples
|
|
96
|
+
- Create, list, update, delete memories
|
|
97
|
+
- Add individual translations
|
|
98
|
+
- Multiple memory operations
|
|
99
|
+
- TMX file import with progress monitoring
|
|
100
|
+
- Translation deletion
|
|
101
|
+
- Translation with TUID and context
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
cd examples
|
|
105
|
+
node memories_management.js
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### Glossary Management
|
|
109
|
+
- **[glossaries_management.js](examples/glossaries_management.js)** - Glossary management examples
|
|
110
|
+
- Create, list, update, delete glossaries
|
|
111
|
+
- CSV import with status monitoring
|
|
112
|
+
- Glossary export
|
|
113
|
+
- Glossary terms count
|
|
114
|
+
- Import status checking
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
cd examples
|
|
118
|
+
node glossaries_management.js
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## π§ API Reference
|
|
122
|
+
|
|
123
|
+
### Core Components
|
|
124
|
+
|
|
125
|
+
### π Authentication
|
|
126
|
+
|
|
127
|
+
The SDK supports authentication via access key and secret:
|
|
128
|
+
|
|
129
|
+
```javascript
|
|
130
|
+
const credentials = new Credentials("your-access-key-id", "your-access-key-secret");
|
|
131
|
+
const lara = new Translator(credentials);
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
**Environment Variables (Recommended):**
|
|
135
|
+
```bash
|
|
136
|
+
export LARA_ACCESS_KEY_ID="your-access-key-id"
|
|
137
|
+
export LARA_ACCESS_KEY_SECRET="your-access-key-secret"
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
```javascript
|
|
141
|
+
const credentials = new Credentials(
|
|
142
|
+
process.env.LARA_ACCESS_KEY_ID,
|
|
143
|
+
process.env.LARA_ACCESS_KEY_SECRET
|
|
144
|
+
);
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
### π Translator
|
|
149
|
+
|
|
150
|
+
```javascript
|
|
151
|
+
// Create translator with credentials
|
|
152
|
+
const lara = new Translator(credentials);
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
#### Text Translation
|
|
156
|
+
|
|
157
|
+
```javascript
|
|
158
|
+
// Basic translation
|
|
159
|
+
const result = await lara.translate("Hello", "en-US", "fr-FR");
|
|
160
|
+
|
|
161
|
+
// Multiple strings
|
|
162
|
+
const result = await lara.translate(["Hello", "World"], "en-US", "fr-FR");
|
|
163
|
+
|
|
164
|
+
// TextBlocks (mixed translatable/non-translatable content)
|
|
165
|
+
const textBlocks = [
|
|
166
|
+
{ text: "Translatable text", translatable: true },
|
|
167
|
+
{ text: "<br>", translatable: false }, // Non-translatable HTML
|
|
168
|
+
{ text: "More translatable text", translatable: true }
|
|
169
|
+
];
|
|
170
|
+
const result = await lara.translate(textBlocks, "en-US", "fr-FR");
|
|
171
|
+
|
|
172
|
+
// With advanced options
|
|
173
|
+
const options = {
|
|
174
|
+
instructions: ["Formal tone"],
|
|
175
|
+
adaptTo: ["mem_1A2b3C4d5E6f7G8h9I0jKl"], // Replace with actual memory IDs
|
|
176
|
+
glossaries: ["gls_1A2b3C4d5E6f7G8h9I0jKl"], // Replace with actual glossary IDs
|
|
177
|
+
style: "fluid",
|
|
178
|
+
timeoutInMillis: 10000
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
const result = await lara.translate("Hello", "en-US", "fr-FR", options);
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
### π Document Translation
|
|
185
|
+
#### Simple document translation
|
|
186
|
+
|
|
187
|
+
```javascript
|
|
188
|
+
const fs = require('fs');
|
|
189
|
+
|
|
190
|
+
const fileStream = fs.createReadStream("/path/to/your/document.txt"); // Replace with actual file path
|
|
191
|
+
const translatedContent = await lara.documents.translate(fileStream, "document.txt", "en-US", "fr-FR");
|
|
192
|
+
|
|
193
|
+
// With options
|
|
194
|
+
const options = {
|
|
195
|
+
adaptTo: ["mem_1A2b3C4d5E6f7G8h9I0jKl"], // Replace with actual memory IDs
|
|
196
|
+
glossaries: ["gls_1A2b3C4d5E6f7G8h9I0jKl"], // Replace with actual glossary IDs
|
|
197
|
+
style: "fluid"
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
const translatedContent = await lara.documents.translate(fileStream, "document.txt", "en-US", "fr-FR", options);
|
|
201
|
+
```
|
|
202
|
+
### Document translation with status monitoring
|
|
203
|
+
#### Document upload
|
|
204
|
+
```javascript
|
|
205
|
+
//Optional: upload options
|
|
206
|
+
const uploadOptions = {
|
|
207
|
+
adaptTo: ["mem_1A2b3C4d5E6f7G8h9I0jKl"], // Replace with actual memory IDs
|
|
208
|
+
glossaries: ["gls_1A2b3C4d5E6f7G8h9I0jKl"] // Replace with actual glossary IDs
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
const document = await lara.documents.upload(fileStream, "document.txt", "en-US", "fr-FR", uploadOptions);
|
|
212
|
+
```
|
|
213
|
+
#### Document translation status monitoring
|
|
214
|
+
```javascript
|
|
215
|
+
const status = await lara.documents.status(document.id);
|
|
216
|
+
```
|
|
217
|
+
#### Download translated document
|
|
218
|
+
```javascript
|
|
219
|
+
const translatedContent = await lara.documents.download(document.id);
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
### π§ Memory Management
|
|
223
|
+
|
|
224
|
+
```javascript
|
|
225
|
+
// Create memory
|
|
226
|
+
const memory = await lara.memories.create("MyMemory");
|
|
227
|
+
|
|
228
|
+
// Create memory with external ID (MyMemory integration)
|
|
229
|
+
const memory = await lara.memories.create("Memory from MyMemory", "aabb1122"); // Replace with actual external ID
|
|
230
|
+
|
|
231
|
+
// Important: To update/overwrite a translation unit you must provide a tuid. Calls without a tuid always create a new unit and will not update existing entries.
|
|
232
|
+
// Add translation to single memory
|
|
233
|
+
const memoryImport = await lara.memories.addTranslation("mem_1A2b3C4d5E6f7G8h9I0jKl", "en-US", "fr-FR", "Hello", "Bonjour", "greeting_001");
|
|
234
|
+
|
|
235
|
+
// Add translation to multiple memories
|
|
236
|
+
const memoryImport = await lara.memories.addTranslation(["mem_1A2b3C4d5E6f7G8h9I0jKl", "mem_2XyZ9AbC8dEf7GhI6jKlMn"], "en-US", "fr-FR", "Hello", "Bonjour", "greeting_002");
|
|
237
|
+
|
|
238
|
+
// Add with context
|
|
239
|
+
const memoryImport = await lara.memories.addTranslation(
|
|
240
|
+
"mem_1A2b3C4d5E6f7G8h9I0jKl", "en-US", "fr-FR", "Hello", "Bonjour", "tuid",
|
|
241
|
+
"sentenceBefore", "sentenceAfter"
|
|
242
|
+
);
|
|
243
|
+
|
|
244
|
+
// TMX import from file
|
|
245
|
+
const tmxFileStream = fs.createReadStream("/path/to/your/memory.tmx"); // Replace with actual TMX file path
|
|
246
|
+
const memoryImport = await lara.memories.importTmx("mem_1A2b3C4d5E6f7G8h9I0jKl", tmxFileStream);
|
|
247
|
+
|
|
248
|
+
// Delete translation
|
|
249
|
+
// Important: if you omit tuid, all entries that match the provided fields will be removed
|
|
250
|
+
const deleteJob = await lara.memories.deleteTranslation(
|
|
251
|
+
"mem_1A2b3C4d5E6f7G8h9I0jKl", "en-US", "fr-FR", "Hello", "Bonjour", tuid="greeting_001"
|
|
252
|
+
);
|
|
253
|
+
|
|
254
|
+
// Wait for import completion
|
|
255
|
+
const completedImport = await lara.memories.waitForImport(memoryImport, undefined, 300000); // 5 minutes
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
### π Glossary Management
|
|
259
|
+
|
|
260
|
+
```javascript
|
|
261
|
+
// Create glossary
|
|
262
|
+
const glossary = await lara.glossaries.create("MyGlossary");
|
|
263
|
+
|
|
264
|
+
// Import CSV from file
|
|
265
|
+
const csvFileStream = fs.createReadStream("/path/to/your/glossary.csv"); // Replace with actual CSV file path
|
|
266
|
+
const glossaryImport = await lara.glossaries.importCsv("gls_1A2b3C4d5E6f7G8h9I0jKl", csvFileStream);
|
|
267
|
+
|
|
268
|
+
// Check import status
|
|
269
|
+
const importStatus = await lara.glossaries.getImportStatus("gls_1A2b3C4d5E6f7G8h9I0jKl");
|
|
270
|
+
|
|
271
|
+
// Wait for import completion
|
|
272
|
+
const completedImport = await lara.glossaries.waitForImport(glossaryImport, undefined, 300000); // 5 minutes
|
|
273
|
+
|
|
274
|
+
// Export glossary
|
|
275
|
+
const csvData = await lara.glossaries.export("gls_1A2b3C4d5E6f7G8h9I0jKl", "csv/table-uni", "en-US");
|
|
276
|
+
|
|
277
|
+
// Get glossary terms count
|
|
278
|
+
const counts = await lara.glossaries.counts("gls_1A2b3C4d5E6f7G8h9I0jKl");
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
### Translation Options
|
|
282
|
+
|
|
283
|
+
```javascript
|
|
284
|
+
const TranslateOptions = {
|
|
285
|
+
adaptTo: ["mem_1A2b3C4d5E6f7G8h9I0jKl"], // Memory IDs to adapt to
|
|
286
|
+
glossaries: ["gls_1A2b3C4d5E6f7G8h9I0jKl"], // Glossary IDs to use
|
|
287
|
+
instructions: ["instruction"], // Translation instructions
|
|
288
|
+
style: "fluid", // Translation style (fluid, faithful, creative)
|
|
289
|
+
contentType: "text/plain", // Content type (text/plain, text/html, etc.)
|
|
290
|
+
multiline: true, // Enable multiline translation
|
|
291
|
+
timeoutInMillis: 10000, // Request timeout in milliseconds
|
|
292
|
+
sourceHint: "en", // Hint for source language detection
|
|
293
|
+
noTrace: false, // Disable request tracing
|
|
294
|
+
verbose: false, // Enable verbose response
|
|
295
|
+
};
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
### Language Codes
|
|
299
|
+
|
|
300
|
+
The SDK supports full language codes (e.g., `en-US`, `fr-FR`, `es-ES`) as well as simple codes (e.g., `en`, `fr`, `es`):
|
|
301
|
+
|
|
302
|
+
```javascript
|
|
303
|
+
// Full language codes (recommended)
|
|
304
|
+
const result = await lara.translate("Hello", "en-US", "fr-FR");
|
|
305
|
+
|
|
306
|
+
// Simple language codes
|
|
307
|
+
const result = await lara.translate("Hello", "en", "fr");
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
### π Supported Languages
|
|
311
|
+
|
|
312
|
+
The SDK supports all languages available in the Lara API. Use the `getLanguages()` method to get the current list:
|
|
313
|
+
|
|
314
|
+
```javascript
|
|
315
|
+
const languages = await lara.getLanguages();
|
|
316
|
+
console.log("Supported languages: " + languages.join(', '));
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
## βοΈ Configuration
|
|
320
|
+
|
|
321
|
+
### Error Handling
|
|
322
|
+
|
|
323
|
+
The SDK provides detailed error information:
|
|
324
|
+
|
|
325
|
+
```javascript
|
|
326
|
+
try {
|
|
327
|
+
const result = await lara.translate("Hello", "en-US", "fr-FR");
|
|
328
|
+
console.log("Translation: " + result.translation);
|
|
329
|
+
} catch (error) {
|
|
330
|
+
if (error.constructor.name === 'LaraApiError') {
|
|
331
|
+
console.error("API Error [" + error.statusCode + "]: " + error.message);
|
|
332
|
+
console.error("Error type: " + error.type);
|
|
333
|
+
} else {
|
|
334
|
+
console.error("SDK Error: " + error.message);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
## π Requirements
|
|
340
|
+
|
|
341
|
+
- Node.js 12 or higher
|
|
342
|
+
- npm or yarn
|
|
343
|
+
- Valid Lara API credentials
|
|
344
|
+
|
|
345
|
+
## π§ͺ Testing
|
|
346
|
+
|
|
347
|
+
Run the examples to test your setup:
|
|
348
|
+
|
|
349
|
+
```bash
|
|
350
|
+
# All examples use environment variables for credentials, so set them first:
|
|
351
|
+
export LARA_ACCESS_KEY_ID="your-access-key-id"
|
|
352
|
+
export LARA_ACCESS_KEY_SECRET="your-access-key-secret"
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
```bash
|
|
356
|
+
# Run basic text translation example
|
|
357
|
+
cd examples
|
|
358
|
+
node text_translation.js
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
## π License
|
|
362
|
+
|
|
363
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
364
|
+
|
|
365
|
+
Happy translating! πβ¨
|
|
@@ -24,10 +24,13 @@ class BrowserLaraClient extends client_1.LaraClient {
|
|
|
24
24
|
for (const [key, value] of Object.entries(body)) {
|
|
25
25
|
if (!value)
|
|
26
26
|
continue;
|
|
27
|
-
if (Array.isArray(value))
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
if (Array.isArray(value)) {
|
|
28
|
+
for (const v of value)
|
|
29
|
+
formBody.append(key, v);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
30
32
|
formBody.append(key, value);
|
|
33
|
+
}
|
|
31
34
|
}
|
|
32
35
|
requestBody = formBody;
|
|
33
36
|
}
|
package/lib/net/index.js
CHANGED
|
@@ -14,7 +14,7 @@ function create(accessKeyId, accessKeySecret, baseUrl) {
|
|
|
14
14
|
const parsedURL = {
|
|
15
15
|
secure: url.protocol === "https:",
|
|
16
16
|
hostname: url.hostname,
|
|
17
|
-
port: url.port ? parseInt(url.port) : url.protocol === "https:" ? 443 : 80
|
|
17
|
+
port: url.port ? parseInt(url.port, 10) : url.protocol === "https:" ? 443 : 80
|
|
18
18
|
};
|
|
19
19
|
if (typeof window !== "undefined")
|
|
20
20
|
return new browser_client_1.BrowserLaraClient(parsedURL, accessKeyId, accessKeySecret);
|
package/lib/net/node-client.js
CHANGED
|
@@ -25,10 +25,13 @@ class NodeLaraClient extends client_1.LaraClient {
|
|
|
25
25
|
for (const [key, value] of Object.entries(body)) {
|
|
26
26
|
if (!value)
|
|
27
27
|
continue;
|
|
28
|
-
if (Array.isArray(value))
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
if (Array.isArray(value)) {
|
|
29
|
+
for (const v of value)
|
|
30
|
+
formBody.append(key, v);
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
31
33
|
formBody.append(key, value);
|
|
34
|
+
}
|
|
32
35
|
}
|
|
33
36
|
headers = {
|
|
34
37
|
...headers,
|
package/lib/sdk-version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "1.6.
|
|
1
|
+
export declare const version = "1.6.6";
|
package/lib/sdk-version.js
CHANGED
|
@@ -26,7 +26,11 @@ export declare enum DocumentStatus {
|
|
|
26
26
|
TRANSLATED = "translated",
|
|
27
27
|
ERROR = "error"
|
|
28
28
|
}
|
|
29
|
-
export
|
|
29
|
+
export interface DocxExtractionParams {
|
|
30
|
+
extractComments?: boolean;
|
|
31
|
+
acceptRevisions?: boolean;
|
|
32
|
+
}
|
|
33
|
+
export type DocumentOptions = {
|
|
30
34
|
adaptTo?: string[];
|
|
31
35
|
glossaries?: string[];
|
|
32
36
|
noTrace?: boolean;
|
|
@@ -35,8 +39,10 @@ export type DocumentUploadOptions = {
|
|
|
35
39
|
export type DocumentDownloadOptions = {
|
|
36
40
|
outputFormat?: string;
|
|
37
41
|
};
|
|
38
|
-
export
|
|
39
|
-
|
|
42
|
+
export type DocumentUploadOptions = DocumentOptions & {
|
|
43
|
+
password?: string;
|
|
44
|
+
extractionParams?: DocxExtractionParams;
|
|
45
|
+
};
|
|
40
46
|
export interface Document {
|
|
41
47
|
readonly id: string;
|
|
42
48
|
readonly status: DocumentStatus;
|
|
@@ -17,7 +17,7 @@ export declare class Memories {
|
|
|
17
17
|
update(id: string, name: string): Promise<Memory>;
|
|
18
18
|
connect<T extends string | string[]>(ids: T): Promise<T extends string ? Memory : Memory[]>;
|
|
19
19
|
importTmx(id: string, tmx: MultiPartFile, gzip?: boolean): Promise<MemoryImport>;
|
|
20
|
-
addTranslation(id: string | string[], source: string, target: string, sentence: string, translation: string, tuid?: string, sentenceBefore?: string, sentenceAfter?: string): Promise<MemoryImport>;
|
|
20
|
+
addTranslation(id: string | string[], source: string, target: string, sentence: string, translation: string, tuid?: string, sentenceBefore?: string, sentenceAfter?: string, headers?: Record<string, string>): Promise<MemoryImport>;
|
|
21
21
|
deleteTranslation(id: string | string[], source: string, target: string, sentence: string, translation: string, tuid?: string, sentenceBefore?: string, sentenceAfter?: string): Promise<MemoryImport>;
|
|
22
22
|
getImportStatus(id: string): Promise<MemoryImport>;
|
|
23
23
|
waitForImport(mImport: MemoryImport, updateCallback?: MemoryImportCallback, maxWaitTime?: number): Promise<MemoryImport>;
|
|
@@ -8,6 +8,7 @@ const errors_1 = require("../errors");
|
|
|
8
8
|
const net_1 = __importDefault(require("../net"));
|
|
9
9
|
const s3_1 = __importDefault(require("../net/s3"));
|
|
10
10
|
const models_1 = require("./models");
|
|
11
|
+
const toSnakeCase_1 = __importDefault(require("../utils/toSnakeCase"));
|
|
11
12
|
class Memories {
|
|
12
13
|
constructor(client) {
|
|
13
14
|
this.client = client;
|
|
@@ -52,7 +53,7 @@ class Memories {
|
|
|
52
53
|
tmx
|
|
53
54
|
});
|
|
54
55
|
}
|
|
55
|
-
async addTranslation(id, source, target, sentence, translation, tuid, sentenceBefore, sentenceAfter) {
|
|
56
|
+
async addTranslation(id, source, target, sentence, translation, tuid, sentenceBefore, sentenceAfter, headers) {
|
|
56
57
|
const body = {
|
|
57
58
|
source,
|
|
58
59
|
target,
|
|
@@ -64,10 +65,10 @@ class Memories {
|
|
|
64
65
|
};
|
|
65
66
|
if (Array.isArray(id)) {
|
|
66
67
|
body.ids = id;
|
|
67
|
-
return await this.client.put("/memories/content", body);
|
|
68
|
+
return await this.client.put("/memories/content", body, undefined, headers);
|
|
68
69
|
}
|
|
69
70
|
else {
|
|
70
|
-
return await this.client.put(`/memories/${id}/content`, body);
|
|
71
|
+
return await this.client.put(`/memories/${id}/content`, body, undefined, headers);
|
|
71
72
|
}
|
|
72
73
|
}
|
|
73
74
|
async deleteTranslation(id, source, target, sentence, translation, tuid, sentenceBefore, sentenceAfter) {
|
|
@@ -120,7 +121,9 @@ class Documents {
|
|
|
120
121
|
s3key: fields.key,
|
|
121
122
|
adapt_to: options === null || options === void 0 ? void 0 : options.adaptTo,
|
|
122
123
|
glossaries: options === null || options === void 0 ? void 0 : options.glossaries,
|
|
123
|
-
style: options === null || options === void 0 ? void 0 : options.style
|
|
124
|
+
style: options === null || options === void 0 ? void 0 : options.style,
|
|
125
|
+
password: options === null || options === void 0 ? void 0 : options.password,
|
|
126
|
+
extraction_params: (options === null || options === void 0 ? void 0 : options.extractionParams) ? (0, toSnakeCase_1.default)(options.extractionParams) : undefined
|
|
124
127
|
}, undefined, headers);
|
|
125
128
|
}
|
|
126
129
|
async status(id) {
|
|
@@ -137,7 +140,9 @@ class Documents {
|
|
|
137
140
|
adaptTo: options === null || options === void 0 ? void 0 : options.adaptTo,
|
|
138
141
|
glossaries: options === null || options === void 0 ? void 0 : options.glossaries,
|
|
139
142
|
noTrace: options === null || options === void 0 ? void 0 : options.noTrace,
|
|
140
|
-
style: options === null || options === void 0 ? void 0 : options.style
|
|
143
|
+
style: options === null || options === void 0 ? void 0 : options.style,
|
|
144
|
+
password: options === null || options === void 0 ? void 0 : options.password,
|
|
145
|
+
extractionParams: options === null || options === void 0 ? void 0 : options.extractionParams
|
|
141
146
|
};
|
|
142
147
|
const { id } = await this.upload(file, filename, source, target, uploadOptions);
|
|
143
148
|
const downloadOptions = (options === null || options === void 0 ? void 0 : options.outputFormat) ? { outputFormat: options.outputFormat } : undefined;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const toSnakeCase = (content) => {
|
|
4
|
+
if (typeof content === 'string')
|
|
5
|
+
return content;
|
|
6
|
+
if (Array.isArray(content))
|
|
7
|
+
return content.map(toSnakeCase);
|
|
8
|
+
if (typeof content === 'object' && content !== null) {
|
|
9
|
+
const result = {};
|
|
10
|
+
for (const [key, value] of Object.entries(content)) {
|
|
11
|
+
const snakeKey = key.replace(/([A-Z])/g, '_$1').toLowerCase();
|
|
12
|
+
result[snakeKey] = toSnakeCase(value);
|
|
13
|
+
}
|
|
14
|
+
return result;
|
|
15
|
+
}
|
|
16
|
+
return content;
|
|
17
|
+
};
|
|
18
|
+
exports.default = toSnakeCase;
|