@lingo.dev/_sdk 0.9.6 → 0.10.0
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/build/index.cjs +44 -22
- package/build/index.d.cts +18 -8
- package/build/index.d.ts +18 -8
- package/build/index.mjs +44 -22
- package/package.json +1 -1
package/build/index.cjs
CHANGED
@@ -30,10 +30,11 @@ var LingoDotDevEngine = class {
|
|
30
30
|
* @param payload - The content to be localized
|
31
31
|
* @param params - Localization parameters including source/target locales and fast mode option
|
32
32
|
* @param progressCallback - Optional callback function to report progress (0-100)
|
33
|
+
* @param signal - Optional AbortSignal to cancel the operation
|
33
34
|
* @returns Localized content
|
34
35
|
* @internal
|
35
36
|
*/
|
36
|
-
async _localizeRaw(payload, params, progressCallback) {
|
37
|
+
async _localizeRaw(payload, params, progressCallback, signal) {
|
37
38
|
const finalPayload = payloadSchema.parse(payload);
|
38
39
|
const finalParams = localizationParamsSchema.parse(params);
|
39
40
|
const chunkedPayload = this.extractPayloadChunks(finalPayload);
|
@@ -49,7 +50,8 @@ var LingoDotDevEngine = class {
|
|
49
50
|
finalParams.targetLocale,
|
50
51
|
{ data: chunk, reference: params.reference },
|
51
52
|
workflowId,
|
52
|
-
params.fast || false
|
53
|
+
params.fast || false,
|
54
|
+
signal
|
53
55
|
);
|
54
56
|
if (progressCallback) {
|
55
57
|
progressCallback(percentageCompleted, chunk, processedPayloadChunk);
|
@@ -63,9 +65,12 @@ var LingoDotDevEngine = class {
|
|
63
65
|
* @param sourceLocale - Source locale
|
64
66
|
* @param targetLocale - Target locale
|
65
67
|
* @param payload - Payload containing the chunk to be localized
|
68
|
+
* @param workflowId - Workflow ID for tracking
|
69
|
+
* @param fast - Whether to use fast mode
|
70
|
+
* @param signal - Optional AbortSignal to cancel the operation
|
66
71
|
* @returns Localized chunk
|
67
72
|
*/
|
68
|
-
async localizeChunk(sourceLocale, targetLocale, payload, workflowId, fast) {
|
73
|
+
async localizeChunk(sourceLocale, targetLocale, payload, workflowId, fast, signal) {
|
69
74
|
const res = await fetch(`${this.config.apiUrl}/i18n`, {
|
70
75
|
method: "POST",
|
71
76
|
headers: {
|
@@ -84,7 +89,8 @@ var LingoDotDevEngine = class {
|
|
84
89
|
},
|
85
90
|
null,
|
86
91
|
2
|
87
|
-
)
|
92
|
+
),
|
93
|
+
signal
|
88
94
|
});
|
89
95
|
if (!res.ok) {
|
90
96
|
if (res.status >= 500 && res.status < 600) {
|
@@ -158,10 +164,11 @@ var LingoDotDevEngine = class {
|
|
158
164
|
* - targetLocale: The target language code (e.g., 'es')
|
159
165
|
* - fast: Optional boolean to enable fast mode (faster but potentially lower quality)
|
160
166
|
* @param progressCallback - Optional callback function to report progress (0-100)
|
167
|
+
* @param signal - Optional AbortSignal to cancel the operation
|
161
168
|
* @returns A new object with the same structure but localized string values
|
162
169
|
*/
|
163
|
-
async localizeObject(obj, params, progressCallback) {
|
164
|
-
return this._localizeRaw(obj, params, progressCallback);
|
170
|
+
async localizeObject(obj, params, progressCallback, signal) {
|
171
|
+
return this._localizeRaw(obj, params, progressCallback, signal);
|
165
172
|
}
|
166
173
|
/**
|
167
174
|
* Localize a single text string
|
@@ -171,13 +178,15 @@ var LingoDotDevEngine = class {
|
|
171
178
|
* - targetLocale: The target language code (e.g., 'es')
|
172
179
|
* - fast: Optional boolean to enable fast mode (faster for bigger batches)
|
173
180
|
* @param progressCallback - Optional callback function to report progress (0-100)
|
181
|
+
* @param signal - Optional AbortSignal to cancel the operation
|
174
182
|
* @returns The localized text string
|
175
183
|
*/
|
176
|
-
async localizeText(text, params, progressCallback) {
|
184
|
+
async localizeText(text, params, progressCallback, signal) {
|
177
185
|
const response = await this._localizeRaw(
|
178
186
|
{ text },
|
179
187
|
params,
|
180
|
-
progressCallback
|
188
|
+
progressCallback,
|
189
|
+
signal
|
181
190
|
);
|
182
191
|
return response.text || "";
|
183
192
|
}
|
@@ -188,16 +197,22 @@ var LingoDotDevEngine = class {
|
|
188
197
|
* - sourceLocale: The source language code (e.g., 'en')
|
189
198
|
* - targetLocales: An array of target language codes (e.g., ['es', 'fr'])
|
190
199
|
* - fast: Optional boolean to enable fast mode (for bigger batches)
|
200
|
+
* @param signal - Optional AbortSignal to cancel the operation
|
191
201
|
* @returns An array of localized text strings
|
192
202
|
*/
|
193
|
-
async batchLocalizeText(text, params) {
|
203
|
+
async batchLocalizeText(text, params, signal) {
|
194
204
|
const responses = await Promise.all(
|
195
205
|
params.targetLocales.map(
|
196
|
-
(targetLocale) => this.localizeText(
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
206
|
+
(targetLocale) => this.localizeText(
|
207
|
+
text,
|
208
|
+
{
|
209
|
+
sourceLocale: params.sourceLocale,
|
210
|
+
targetLocale,
|
211
|
+
fast: params.fast
|
212
|
+
},
|
213
|
+
void 0,
|
214
|
+
signal
|
215
|
+
)
|
201
216
|
)
|
202
217
|
);
|
203
218
|
return responses;
|
@@ -210,13 +225,15 @@ var LingoDotDevEngine = class {
|
|
210
225
|
* - targetLocale: The target language code (e.g., 'es')
|
211
226
|
* - fast: Optional boolean to enable fast mode (faster but potentially lower quality)
|
212
227
|
* @param progressCallback - Optional callback function to report progress (0-100)
|
228
|
+
* @param signal - Optional AbortSignal to cancel the operation
|
213
229
|
* @returns Array of localized chat messages with preserved structure
|
214
230
|
*/
|
215
|
-
async localizeChat(chat, params, progressCallback) {
|
231
|
+
async localizeChat(chat, params, progressCallback, signal) {
|
216
232
|
const localized = await this._localizeRaw(
|
217
233
|
{ chat },
|
218
234
|
params,
|
219
|
-
progressCallback
|
235
|
+
progressCallback,
|
236
|
+
signal
|
220
237
|
);
|
221
238
|
return Object.entries(localized).map(([key, value]) => ({
|
222
239
|
name: chat[parseInt(key.split("_")[1])].name,
|
@@ -232,9 +249,10 @@ var LingoDotDevEngine = class {
|
|
232
249
|
* - targetLocale: The target language code (e.g., 'es')
|
233
250
|
* - fast: Optional boolean to enable fast mode (faster but potentially lower quality)
|
234
251
|
* @param progressCallback - Optional callback function to report progress (0-100)
|
252
|
+
* @param signal - Optional AbortSignal to cancel the operation
|
235
253
|
* @returns The localized HTML document as a string, with updated lang attribute
|
236
254
|
*/
|
237
|
-
async localizeHtml(html, params, progressCallback) {
|
255
|
+
async localizeHtml(html, params, progressCallback, signal) {
|
238
256
|
const jsdomPackage = await Promise.resolve().then(() => _interopRequireWildcard(require("jsdom")));
|
239
257
|
const { JSDOM } = jsdomPackage;
|
240
258
|
const dom = new JSDOM(html);
|
@@ -307,7 +325,8 @@ var LingoDotDevEngine = class {
|
|
307
325
|
const localizedContent = await this._localizeRaw(
|
308
326
|
extractedContent,
|
309
327
|
params,
|
310
|
-
progressCallback
|
328
|
+
progressCallback,
|
329
|
+
signal
|
311
330
|
);
|
312
331
|
document.documentElement.setAttribute("lang", params.targetLocale);
|
313
332
|
Object.entries(localizedContent).forEach(([path, value]) => {
|
@@ -337,16 +356,18 @@ var LingoDotDevEngine = class {
|
|
337
356
|
/**
|
338
357
|
* Detect the language of a given text
|
339
358
|
* @param text - The text to analyze
|
359
|
+
* @param signal - Optional AbortSignal to cancel the operation
|
340
360
|
* @returns Promise resolving to a locale code (e.g., 'en', 'es', 'fr')
|
341
361
|
*/
|
342
|
-
async recognizeLocale(text) {
|
362
|
+
async recognizeLocale(text, signal) {
|
343
363
|
const response = await fetch(`${this.config.apiUrl}/recognize`, {
|
344
364
|
method: "POST",
|
345
365
|
headers: {
|
346
366
|
"Content-Type": "application/json; charset=utf-8",
|
347
367
|
Authorization: `Bearer ${this.config.apiKey}`
|
348
368
|
},
|
349
|
-
body: JSON.stringify({ text })
|
369
|
+
body: JSON.stringify({ text }),
|
370
|
+
signal
|
350
371
|
});
|
351
372
|
if (!response.ok) {
|
352
373
|
if (response.status >= 500 && response.status < 600) {
|
@@ -359,14 +380,15 @@ var LingoDotDevEngine = class {
|
|
359
380
|
const jsonResponse = await response.json();
|
360
381
|
return jsonResponse.locale;
|
361
382
|
}
|
362
|
-
async whoami() {
|
383
|
+
async whoami(signal) {
|
363
384
|
try {
|
364
385
|
const res = await fetch(`${this.config.apiUrl}/whoami`, {
|
365
386
|
method: "POST",
|
366
387
|
headers: {
|
367
388
|
Authorization: `Bearer ${this.config.apiKey}`,
|
368
389
|
ContentType: "application/json"
|
369
|
-
}
|
390
|
+
},
|
391
|
+
signal
|
370
392
|
});
|
371
393
|
if (res.ok) {
|
372
394
|
const payload = await res.json();
|
package/build/index.d.cts
CHANGED
@@ -51,15 +51,19 @@ declare class LingoDotDevEngine {
|
|
51
51
|
* @param payload - The content to be localized
|
52
52
|
* @param params - Localization parameters including source/target locales and fast mode option
|
53
53
|
* @param progressCallback - Optional callback function to report progress (0-100)
|
54
|
+
* @param signal - Optional AbortSignal to cancel the operation
|
54
55
|
* @returns Localized content
|
55
56
|
* @internal
|
56
57
|
*/
|
57
|
-
_localizeRaw(payload: Z.infer<typeof payloadSchema>, params: Z.infer<typeof localizationParamsSchema>, progressCallback?: (progress: number, sourceChunk: Record<string, string>, processedChunk: Record<string, string>) => void): Promise<Record<string, string>>;
|
58
|
+
_localizeRaw(payload: Z.infer<typeof payloadSchema>, params: Z.infer<typeof localizationParamsSchema>, progressCallback?: (progress: number, sourceChunk: Record<string, string>, processedChunk: Record<string, string>) => void, signal?: AbortSignal): Promise<Record<string, string>>;
|
58
59
|
/**
|
59
60
|
* Localize a single chunk of content
|
60
61
|
* @param sourceLocale - Source locale
|
61
62
|
* @param targetLocale - Target locale
|
62
63
|
* @param payload - Payload containing the chunk to be localized
|
64
|
+
* @param workflowId - Workflow ID for tracking
|
65
|
+
* @param fast - Whether to use fast mode
|
66
|
+
* @param signal - Optional AbortSignal to cancel the operation
|
63
67
|
* @returns Localized chunk
|
64
68
|
*/
|
65
69
|
private localizeChunk;
|
@@ -83,9 +87,10 @@ declare class LingoDotDevEngine {
|
|
83
87
|
* - targetLocale: The target language code (e.g., 'es')
|
84
88
|
* - fast: Optional boolean to enable fast mode (faster but potentially lower quality)
|
85
89
|
* @param progressCallback - Optional callback function to report progress (0-100)
|
90
|
+
* @param signal - Optional AbortSignal to cancel the operation
|
86
91
|
* @returns A new object with the same structure but localized string values
|
87
92
|
*/
|
88
|
-
localizeObject(obj: Record<string, any>, params: Z.infer<typeof localizationParamsSchema>, progressCallback?: (progress: number, sourceChunk: Record<string, string>, processedChunk: Record<string, string>) => void): Promise<Record<string, any>>;
|
93
|
+
localizeObject(obj: Record<string, any>, params: Z.infer<typeof localizationParamsSchema>, progressCallback?: (progress: number, sourceChunk: Record<string, string>, processedChunk: Record<string, string>) => void, signal?: AbortSignal): Promise<Record<string, any>>;
|
89
94
|
/**
|
90
95
|
* Localize a single text string
|
91
96
|
* @param text - The text string to be localized
|
@@ -94,9 +99,10 @@ declare class LingoDotDevEngine {
|
|
94
99
|
* - targetLocale: The target language code (e.g., 'es')
|
95
100
|
* - fast: Optional boolean to enable fast mode (faster for bigger batches)
|
96
101
|
* @param progressCallback - Optional callback function to report progress (0-100)
|
102
|
+
* @param signal - Optional AbortSignal to cancel the operation
|
97
103
|
* @returns The localized text string
|
98
104
|
*/
|
99
|
-
localizeText(text: string, params: Z.infer<typeof localizationParamsSchema>, progressCallback?: (progress: number) => void): Promise<string>;
|
105
|
+
localizeText(text: string, params: Z.infer<typeof localizationParamsSchema>, progressCallback?: (progress: number) => void, signal?: AbortSignal): Promise<string>;
|
100
106
|
/**
|
101
107
|
* Localize a text string to multiple target locales
|
102
108
|
* @param text - The text string to be localized
|
@@ -104,13 +110,14 @@ declare class LingoDotDevEngine {
|
|
104
110
|
* - sourceLocale: The source language code (e.g., 'en')
|
105
111
|
* - targetLocales: An array of target language codes (e.g., ['es', 'fr'])
|
106
112
|
* - fast: Optional boolean to enable fast mode (for bigger batches)
|
113
|
+
* @param signal - Optional AbortSignal to cancel the operation
|
107
114
|
* @returns An array of localized text strings
|
108
115
|
*/
|
109
116
|
batchLocalizeText(text: string, params: {
|
110
117
|
sourceLocale: LocaleCode;
|
111
118
|
targetLocales: LocaleCode[];
|
112
119
|
fast?: boolean;
|
113
|
-
}): Promise<string[]>;
|
120
|
+
}, signal?: AbortSignal): Promise<string[]>;
|
114
121
|
/**
|
115
122
|
* Localize a chat sequence while preserving speaker names
|
116
123
|
* @param chat - Array of chat messages, each with 'name' and 'text' properties
|
@@ -119,12 +126,13 @@ declare class LingoDotDevEngine {
|
|
119
126
|
* - targetLocale: The target language code (e.g., 'es')
|
120
127
|
* - fast: Optional boolean to enable fast mode (faster but potentially lower quality)
|
121
128
|
* @param progressCallback - Optional callback function to report progress (0-100)
|
129
|
+
* @param signal - Optional AbortSignal to cancel the operation
|
122
130
|
* @returns Array of localized chat messages with preserved structure
|
123
131
|
*/
|
124
132
|
localizeChat(chat: Array<{
|
125
133
|
name: string;
|
126
134
|
text: string;
|
127
|
-
}>, params: Z.infer<typeof localizationParamsSchema>, progressCallback?: (progress: number) => void): Promise<Array<{
|
135
|
+
}>, params: Z.infer<typeof localizationParamsSchema>, progressCallback?: (progress: number) => void, signal?: AbortSignal): Promise<Array<{
|
128
136
|
name: string;
|
129
137
|
text: string;
|
130
138
|
}>>;
|
@@ -137,16 +145,18 @@ declare class LingoDotDevEngine {
|
|
137
145
|
* - targetLocale: The target language code (e.g., 'es')
|
138
146
|
* - fast: Optional boolean to enable fast mode (faster but potentially lower quality)
|
139
147
|
* @param progressCallback - Optional callback function to report progress (0-100)
|
148
|
+
* @param signal - Optional AbortSignal to cancel the operation
|
140
149
|
* @returns The localized HTML document as a string, with updated lang attribute
|
141
150
|
*/
|
142
|
-
localizeHtml(html: string, params: Z.infer<typeof localizationParamsSchema>, progressCallback?: (progress: number) => void): Promise<string>;
|
151
|
+
localizeHtml(html: string, params: Z.infer<typeof localizationParamsSchema>, progressCallback?: (progress: number) => void, signal?: AbortSignal): Promise<string>;
|
143
152
|
/**
|
144
153
|
* Detect the language of a given text
|
145
154
|
* @param text - The text to analyze
|
155
|
+
* @param signal - Optional AbortSignal to cancel the operation
|
146
156
|
* @returns Promise resolving to a locale code (e.g., 'en', 'es', 'fr')
|
147
157
|
*/
|
148
|
-
recognizeLocale(text: string): Promise<LocaleCode>;
|
149
|
-
whoami(): Promise<{
|
158
|
+
recognizeLocale(text: string, signal?: AbortSignal): Promise<LocaleCode>;
|
159
|
+
whoami(signal?: AbortSignal): Promise<{
|
150
160
|
email: string;
|
151
161
|
id: string;
|
152
162
|
} | null>;
|
package/build/index.d.ts
CHANGED
@@ -51,15 +51,19 @@ declare class LingoDotDevEngine {
|
|
51
51
|
* @param payload - The content to be localized
|
52
52
|
* @param params - Localization parameters including source/target locales and fast mode option
|
53
53
|
* @param progressCallback - Optional callback function to report progress (0-100)
|
54
|
+
* @param signal - Optional AbortSignal to cancel the operation
|
54
55
|
* @returns Localized content
|
55
56
|
* @internal
|
56
57
|
*/
|
57
|
-
_localizeRaw(payload: Z.infer<typeof payloadSchema>, params: Z.infer<typeof localizationParamsSchema>, progressCallback?: (progress: number, sourceChunk: Record<string, string>, processedChunk: Record<string, string>) => void): Promise<Record<string, string>>;
|
58
|
+
_localizeRaw(payload: Z.infer<typeof payloadSchema>, params: Z.infer<typeof localizationParamsSchema>, progressCallback?: (progress: number, sourceChunk: Record<string, string>, processedChunk: Record<string, string>) => void, signal?: AbortSignal): Promise<Record<string, string>>;
|
58
59
|
/**
|
59
60
|
* Localize a single chunk of content
|
60
61
|
* @param sourceLocale - Source locale
|
61
62
|
* @param targetLocale - Target locale
|
62
63
|
* @param payload - Payload containing the chunk to be localized
|
64
|
+
* @param workflowId - Workflow ID for tracking
|
65
|
+
* @param fast - Whether to use fast mode
|
66
|
+
* @param signal - Optional AbortSignal to cancel the operation
|
63
67
|
* @returns Localized chunk
|
64
68
|
*/
|
65
69
|
private localizeChunk;
|
@@ -83,9 +87,10 @@ declare class LingoDotDevEngine {
|
|
83
87
|
* - targetLocale: The target language code (e.g., 'es')
|
84
88
|
* - fast: Optional boolean to enable fast mode (faster but potentially lower quality)
|
85
89
|
* @param progressCallback - Optional callback function to report progress (0-100)
|
90
|
+
* @param signal - Optional AbortSignal to cancel the operation
|
86
91
|
* @returns A new object with the same structure but localized string values
|
87
92
|
*/
|
88
|
-
localizeObject(obj: Record<string, any>, params: Z.infer<typeof localizationParamsSchema>, progressCallback?: (progress: number, sourceChunk: Record<string, string>, processedChunk: Record<string, string>) => void): Promise<Record<string, any>>;
|
93
|
+
localizeObject(obj: Record<string, any>, params: Z.infer<typeof localizationParamsSchema>, progressCallback?: (progress: number, sourceChunk: Record<string, string>, processedChunk: Record<string, string>) => void, signal?: AbortSignal): Promise<Record<string, any>>;
|
89
94
|
/**
|
90
95
|
* Localize a single text string
|
91
96
|
* @param text - The text string to be localized
|
@@ -94,9 +99,10 @@ declare class LingoDotDevEngine {
|
|
94
99
|
* - targetLocale: The target language code (e.g., 'es')
|
95
100
|
* - fast: Optional boolean to enable fast mode (faster for bigger batches)
|
96
101
|
* @param progressCallback - Optional callback function to report progress (0-100)
|
102
|
+
* @param signal - Optional AbortSignal to cancel the operation
|
97
103
|
* @returns The localized text string
|
98
104
|
*/
|
99
|
-
localizeText(text: string, params: Z.infer<typeof localizationParamsSchema>, progressCallback?: (progress: number) => void): Promise<string>;
|
105
|
+
localizeText(text: string, params: Z.infer<typeof localizationParamsSchema>, progressCallback?: (progress: number) => void, signal?: AbortSignal): Promise<string>;
|
100
106
|
/**
|
101
107
|
* Localize a text string to multiple target locales
|
102
108
|
* @param text - The text string to be localized
|
@@ -104,13 +110,14 @@ declare class LingoDotDevEngine {
|
|
104
110
|
* - sourceLocale: The source language code (e.g., 'en')
|
105
111
|
* - targetLocales: An array of target language codes (e.g., ['es', 'fr'])
|
106
112
|
* - fast: Optional boolean to enable fast mode (for bigger batches)
|
113
|
+
* @param signal - Optional AbortSignal to cancel the operation
|
107
114
|
* @returns An array of localized text strings
|
108
115
|
*/
|
109
116
|
batchLocalizeText(text: string, params: {
|
110
117
|
sourceLocale: LocaleCode;
|
111
118
|
targetLocales: LocaleCode[];
|
112
119
|
fast?: boolean;
|
113
|
-
}): Promise<string[]>;
|
120
|
+
}, signal?: AbortSignal): Promise<string[]>;
|
114
121
|
/**
|
115
122
|
* Localize a chat sequence while preserving speaker names
|
116
123
|
* @param chat - Array of chat messages, each with 'name' and 'text' properties
|
@@ -119,12 +126,13 @@ declare class LingoDotDevEngine {
|
|
119
126
|
* - targetLocale: The target language code (e.g., 'es')
|
120
127
|
* - fast: Optional boolean to enable fast mode (faster but potentially lower quality)
|
121
128
|
* @param progressCallback - Optional callback function to report progress (0-100)
|
129
|
+
* @param signal - Optional AbortSignal to cancel the operation
|
122
130
|
* @returns Array of localized chat messages with preserved structure
|
123
131
|
*/
|
124
132
|
localizeChat(chat: Array<{
|
125
133
|
name: string;
|
126
134
|
text: string;
|
127
|
-
}>, params: Z.infer<typeof localizationParamsSchema>, progressCallback?: (progress: number) => void): Promise<Array<{
|
135
|
+
}>, params: Z.infer<typeof localizationParamsSchema>, progressCallback?: (progress: number) => void, signal?: AbortSignal): Promise<Array<{
|
128
136
|
name: string;
|
129
137
|
text: string;
|
130
138
|
}>>;
|
@@ -137,16 +145,18 @@ declare class LingoDotDevEngine {
|
|
137
145
|
* - targetLocale: The target language code (e.g., 'es')
|
138
146
|
* - fast: Optional boolean to enable fast mode (faster but potentially lower quality)
|
139
147
|
* @param progressCallback - Optional callback function to report progress (0-100)
|
148
|
+
* @param signal - Optional AbortSignal to cancel the operation
|
140
149
|
* @returns The localized HTML document as a string, with updated lang attribute
|
141
150
|
*/
|
142
|
-
localizeHtml(html: string, params: Z.infer<typeof localizationParamsSchema>, progressCallback?: (progress: number) => void): Promise<string>;
|
151
|
+
localizeHtml(html: string, params: Z.infer<typeof localizationParamsSchema>, progressCallback?: (progress: number) => void, signal?: AbortSignal): Promise<string>;
|
143
152
|
/**
|
144
153
|
* Detect the language of a given text
|
145
154
|
* @param text - The text to analyze
|
155
|
+
* @param signal - Optional AbortSignal to cancel the operation
|
146
156
|
* @returns Promise resolving to a locale code (e.g., 'en', 'es', 'fr')
|
147
157
|
*/
|
148
|
-
recognizeLocale(text: string): Promise<LocaleCode>;
|
149
|
-
whoami(): Promise<{
|
158
|
+
recognizeLocale(text: string, signal?: AbortSignal): Promise<LocaleCode>;
|
159
|
+
whoami(signal?: AbortSignal): Promise<{
|
150
160
|
email: string;
|
151
161
|
id: string;
|
152
162
|
} | null>;
|
package/build/index.mjs
CHANGED
@@ -30,10 +30,11 @@ var LingoDotDevEngine = class {
|
|
30
30
|
* @param payload - The content to be localized
|
31
31
|
* @param params - Localization parameters including source/target locales and fast mode option
|
32
32
|
* @param progressCallback - Optional callback function to report progress (0-100)
|
33
|
+
* @param signal - Optional AbortSignal to cancel the operation
|
33
34
|
* @returns Localized content
|
34
35
|
* @internal
|
35
36
|
*/
|
36
|
-
async _localizeRaw(payload, params, progressCallback) {
|
37
|
+
async _localizeRaw(payload, params, progressCallback, signal) {
|
37
38
|
const finalPayload = payloadSchema.parse(payload);
|
38
39
|
const finalParams = localizationParamsSchema.parse(params);
|
39
40
|
const chunkedPayload = this.extractPayloadChunks(finalPayload);
|
@@ -49,7 +50,8 @@ var LingoDotDevEngine = class {
|
|
49
50
|
finalParams.targetLocale,
|
50
51
|
{ data: chunk, reference: params.reference },
|
51
52
|
workflowId,
|
52
|
-
params.fast || false
|
53
|
+
params.fast || false,
|
54
|
+
signal
|
53
55
|
);
|
54
56
|
if (progressCallback) {
|
55
57
|
progressCallback(percentageCompleted, chunk, processedPayloadChunk);
|
@@ -63,9 +65,12 @@ var LingoDotDevEngine = class {
|
|
63
65
|
* @param sourceLocale - Source locale
|
64
66
|
* @param targetLocale - Target locale
|
65
67
|
* @param payload - Payload containing the chunk to be localized
|
68
|
+
* @param workflowId - Workflow ID for tracking
|
69
|
+
* @param fast - Whether to use fast mode
|
70
|
+
* @param signal - Optional AbortSignal to cancel the operation
|
66
71
|
* @returns Localized chunk
|
67
72
|
*/
|
68
|
-
async localizeChunk(sourceLocale, targetLocale, payload, workflowId, fast) {
|
73
|
+
async localizeChunk(sourceLocale, targetLocale, payload, workflowId, fast, signal) {
|
69
74
|
const res = await fetch(`${this.config.apiUrl}/i18n`, {
|
70
75
|
method: "POST",
|
71
76
|
headers: {
|
@@ -84,7 +89,8 @@ var LingoDotDevEngine = class {
|
|
84
89
|
},
|
85
90
|
null,
|
86
91
|
2
|
87
|
-
)
|
92
|
+
),
|
93
|
+
signal
|
88
94
|
});
|
89
95
|
if (!res.ok) {
|
90
96
|
if (res.status >= 500 && res.status < 600) {
|
@@ -158,10 +164,11 @@ var LingoDotDevEngine = class {
|
|
158
164
|
* - targetLocale: The target language code (e.g., 'es')
|
159
165
|
* - fast: Optional boolean to enable fast mode (faster but potentially lower quality)
|
160
166
|
* @param progressCallback - Optional callback function to report progress (0-100)
|
167
|
+
* @param signal - Optional AbortSignal to cancel the operation
|
161
168
|
* @returns A new object with the same structure but localized string values
|
162
169
|
*/
|
163
|
-
async localizeObject(obj, params, progressCallback) {
|
164
|
-
return this._localizeRaw(obj, params, progressCallback);
|
170
|
+
async localizeObject(obj, params, progressCallback, signal) {
|
171
|
+
return this._localizeRaw(obj, params, progressCallback, signal);
|
165
172
|
}
|
166
173
|
/**
|
167
174
|
* Localize a single text string
|
@@ -171,13 +178,15 @@ var LingoDotDevEngine = class {
|
|
171
178
|
* - targetLocale: The target language code (e.g., 'es')
|
172
179
|
* - fast: Optional boolean to enable fast mode (faster for bigger batches)
|
173
180
|
* @param progressCallback - Optional callback function to report progress (0-100)
|
181
|
+
* @param signal - Optional AbortSignal to cancel the operation
|
174
182
|
* @returns The localized text string
|
175
183
|
*/
|
176
|
-
async localizeText(text, params, progressCallback) {
|
184
|
+
async localizeText(text, params, progressCallback, signal) {
|
177
185
|
const response = await this._localizeRaw(
|
178
186
|
{ text },
|
179
187
|
params,
|
180
|
-
progressCallback
|
188
|
+
progressCallback,
|
189
|
+
signal
|
181
190
|
);
|
182
191
|
return response.text || "";
|
183
192
|
}
|
@@ -188,16 +197,22 @@ var LingoDotDevEngine = class {
|
|
188
197
|
* - sourceLocale: The source language code (e.g., 'en')
|
189
198
|
* - targetLocales: An array of target language codes (e.g., ['es', 'fr'])
|
190
199
|
* - fast: Optional boolean to enable fast mode (for bigger batches)
|
200
|
+
* @param signal - Optional AbortSignal to cancel the operation
|
191
201
|
* @returns An array of localized text strings
|
192
202
|
*/
|
193
|
-
async batchLocalizeText(text, params) {
|
203
|
+
async batchLocalizeText(text, params, signal) {
|
194
204
|
const responses = await Promise.all(
|
195
205
|
params.targetLocales.map(
|
196
|
-
(targetLocale) => this.localizeText(
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
206
|
+
(targetLocale) => this.localizeText(
|
207
|
+
text,
|
208
|
+
{
|
209
|
+
sourceLocale: params.sourceLocale,
|
210
|
+
targetLocale,
|
211
|
+
fast: params.fast
|
212
|
+
},
|
213
|
+
void 0,
|
214
|
+
signal
|
215
|
+
)
|
201
216
|
)
|
202
217
|
);
|
203
218
|
return responses;
|
@@ -210,13 +225,15 @@ var LingoDotDevEngine = class {
|
|
210
225
|
* - targetLocale: The target language code (e.g., 'es')
|
211
226
|
* - fast: Optional boolean to enable fast mode (faster but potentially lower quality)
|
212
227
|
* @param progressCallback - Optional callback function to report progress (0-100)
|
228
|
+
* @param signal - Optional AbortSignal to cancel the operation
|
213
229
|
* @returns Array of localized chat messages with preserved structure
|
214
230
|
*/
|
215
|
-
async localizeChat(chat, params, progressCallback) {
|
231
|
+
async localizeChat(chat, params, progressCallback, signal) {
|
216
232
|
const localized = await this._localizeRaw(
|
217
233
|
{ chat },
|
218
234
|
params,
|
219
|
-
progressCallback
|
235
|
+
progressCallback,
|
236
|
+
signal
|
220
237
|
);
|
221
238
|
return Object.entries(localized).map(([key, value]) => ({
|
222
239
|
name: chat[parseInt(key.split("_")[1])].name,
|
@@ -232,9 +249,10 @@ var LingoDotDevEngine = class {
|
|
232
249
|
* - targetLocale: The target language code (e.g., 'es')
|
233
250
|
* - fast: Optional boolean to enable fast mode (faster but potentially lower quality)
|
234
251
|
* @param progressCallback - Optional callback function to report progress (0-100)
|
252
|
+
* @param signal - Optional AbortSignal to cancel the operation
|
235
253
|
* @returns The localized HTML document as a string, with updated lang attribute
|
236
254
|
*/
|
237
|
-
async localizeHtml(html, params, progressCallback) {
|
255
|
+
async localizeHtml(html, params, progressCallback, signal) {
|
238
256
|
const jsdomPackage = await import("jsdom");
|
239
257
|
const { JSDOM } = jsdomPackage;
|
240
258
|
const dom = new JSDOM(html);
|
@@ -307,7 +325,8 @@ var LingoDotDevEngine = class {
|
|
307
325
|
const localizedContent = await this._localizeRaw(
|
308
326
|
extractedContent,
|
309
327
|
params,
|
310
|
-
progressCallback
|
328
|
+
progressCallback,
|
329
|
+
signal
|
311
330
|
);
|
312
331
|
document.documentElement.setAttribute("lang", params.targetLocale);
|
313
332
|
Object.entries(localizedContent).forEach(([path, value]) => {
|
@@ -337,16 +356,18 @@ var LingoDotDevEngine = class {
|
|
337
356
|
/**
|
338
357
|
* Detect the language of a given text
|
339
358
|
* @param text - The text to analyze
|
359
|
+
* @param signal - Optional AbortSignal to cancel the operation
|
340
360
|
* @returns Promise resolving to a locale code (e.g., 'en', 'es', 'fr')
|
341
361
|
*/
|
342
|
-
async recognizeLocale(text) {
|
362
|
+
async recognizeLocale(text, signal) {
|
343
363
|
const response = await fetch(`${this.config.apiUrl}/recognize`, {
|
344
364
|
method: "POST",
|
345
365
|
headers: {
|
346
366
|
"Content-Type": "application/json; charset=utf-8",
|
347
367
|
Authorization: `Bearer ${this.config.apiKey}`
|
348
368
|
},
|
349
|
-
body: JSON.stringify({ text })
|
369
|
+
body: JSON.stringify({ text }),
|
370
|
+
signal
|
350
371
|
});
|
351
372
|
if (!response.ok) {
|
352
373
|
if (response.status >= 500 && response.status < 600) {
|
@@ -359,14 +380,15 @@ var LingoDotDevEngine = class {
|
|
359
380
|
const jsonResponse = await response.json();
|
360
381
|
return jsonResponse.locale;
|
361
382
|
}
|
362
|
-
async whoami() {
|
383
|
+
async whoami(signal) {
|
363
384
|
try {
|
364
385
|
const res = await fetch(`${this.config.apiUrl}/whoami`, {
|
365
386
|
method: "POST",
|
366
387
|
headers: {
|
367
388
|
Authorization: `Bearer ${this.config.apiKey}`,
|
368
389
|
ContentType: "application/json"
|
369
|
-
}
|
390
|
+
},
|
391
|
+
signal
|
370
392
|
});
|
371
393
|
if (res.ok) {
|
372
394
|
const payload = await res.json();
|