lingo.dev 0.74.2 → 0.74.4

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.
@@ -1,331 +0,0 @@
1
- import {
2
- localeCodeSchema
3
- } from "./chunk-B6KMMXCA.mjs";
4
-
5
- // ../sdk/build/index.mjs
6
- import Z from "zod";
7
- import { createId } from "@paralleldrive/cuid2";
8
- var engineParamsSchema = Z.object({
9
- apiKey: Z.string(),
10
- apiUrl: Z.string().url().default("https://engine.lingo.dev"),
11
- batchSize: Z.number().int().gt(0).lte(250).default(25),
12
- idealBatchItemSize: Z.number().int().gt(0).lte(2500).default(250)
13
- }).passthrough();
14
- var payloadSchema = Z.record(Z.string(), Z.any());
15
- var localizationParamsSchema = Z.object({
16
- sourceLocale: localeCodeSchema,
17
- targetLocale: localeCodeSchema,
18
- fast: Z.boolean().optional()
19
- });
20
- var referenceSchema = Z.record(localeCodeSchema, payloadSchema);
21
- var ReplexicaEngine = class {
22
- config;
23
- /**
24
- * Create a new ReplexicaEngine instance
25
- * @param config - Configuration options for the Engine
26
- */
27
- constructor(config) {
28
- this.config = engineParamsSchema.parse(config);
29
- }
30
- /**
31
- * Localize content using the Lingo.dev API
32
- * @param payload - The content to be localized
33
- * @param params - Localization parameters including source/target locales and fast mode option
34
- * @param reference - Optional reference translations to maintain consistency
35
- * @param progressCallback - Optional callback function to report progress (0-100)
36
- * @returns Localized content
37
- * @internal
38
- */
39
- async _localizeRaw(payload, params, reference, progressCallback) {
40
- const finalPayload = payloadSchema.parse(payload);
41
- const finalParams = localizationParamsSchema.parse(params);
42
- const chunkedPayload = this.extractPayloadChunks(finalPayload);
43
- const processedPayloadChunks = [];
44
- const workflowId = createId();
45
- for (let i = 0; i < chunkedPayload.length; i++) {
46
- const chunk = chunkedPayload[i];
47
- const percentageCompleted = Math.round((i + 1) / chunkedPayload.length * 100);
48
- const processedPayloadChunk = await this.localizeChunk(
49
- finalParams.sourceLocale,
50
- finalParams.targetLocale,
51
- { data: chunk, reference },
52
- workflowId,
53
- params.fast || false
54
- );
55
- if (progressCallback) {
56
- progressCallback(percentageCompleted, chunk, processedPayloadChunk);
57
- }
58
- processedPayloadChunks.push(processedPayloadChunk);
59
- }
60
- return Object.assign({}, ...processedPayloadChunks);
61
- }
62
- /**
63
- * Localize a single chunk of content
64
- * @param sourceLocale - Source locale
65
- * @param targetLocale - Target locale
66
- * @param payload - Payload containing the chunk to be localized
67
- * @returns Localized chunk
68
- */
69
- async localizeChunk(sourceLocale, targetLocale, payload, workflowId, fast) {
70
- const res = await fetch(`${this.config.apiUrl}/i18n`, {
71
- method: "POST",
72
- headers: {
73
- "Content-Type": "application/json",
74
- Authorization: `Bearer ${this.config.apiKey}`
75
- },
76
- body: JSON.stringify(
77
- {
78
- params: { workflowId, fast },
79
- locale: {
80
- source: sourceLocale,
81
- target: targetLocale
82
- },
83
- data: payload.data,
84
- reference: payload.reference
85
- },
86
- null,
87
- 2
88
- )
89
- });
90
- if (!res.ok) {
91
- if (res.status === 400) {
92
- throw new Error(`Invalid request: ${res.statusText}`);
93
- } else {
94
- const errorText = await res.text();
95
- throw new Error(errorText);
96
- }
97
- }
98
- const jsonResponse = await res.json();
99
- return jsonResponse.data || {};
100
- }
101
- /**
102
- * Extract payload chunks based on the ideal chunk size
103
- * @param payload - The payload to be chunked
104
- * @returns An array of payload chunks
105
- */
106
- extractPayloadChunks(payload) {
107
- const result = [];
108
- let currentChunk = {};
109
- let currentChunkItemCount = 0;
110
- const payloadEntries = Object.entries(payload);
111
- for (let i = 0; i < payloadEntries.length; i++) {
112
- const [key, value] = payloadEntries[i];
113
- currentChunk[key] = value;
114
- currentChunkItemCount++;
115
- const currentChunkSize = this.countWordsInRecord(currentChunk);
116
- if (currentChunkSize > this.config.idealBatchItemSize || currentChunkItemCount >= this.config.batchSize || i === payloadEntries.length - 1) {
117
- result.push(currentChunk);
118
- currentChunk = {};
119
- currentChunkItemCount = 0;
120
- }
121
- }
122
- return result;
123
- }
124
- /**
125
- * Count words in a record or array
126
- * @param payload - The payload to count words in
127
- * @returns The total number of words
128
- */
129
- countWordsInRecord(payload) {
130
- if (Array.isArray(payload)) {
131
- return payload.reduce((acc, item) => acc + this.countWordsInRecord(item), 0);
132
- } else if (typeof payload === "object" && payload !== null) {
133
- return Object.values(payload).reduce((acc, item) => acc + this.countWordsInRecord(item), 0);
134
- } else if (typeof payload === "string") {
135
- return payload.trim().split(/\s+/).filter(Boolean).length;
136
- } else {
137
- return 0;
138
- }
139
- }
140
- /**
141
- * Localize a typical JavaScript object
142
- * @param obj - The object to be localized (strings will be extracted and translated)
143
- * @param params - Localization parameters:
144
- * - sourceLocale: The source language code (e.g., 'en')
145
- * - targetLocale: The target language code (e.g., 'es')
146
- * - fast: Optional boolean to enable fast mode (faster but potentially lower quality)
147
- * @param progressCallback - Optional callback function to report progress (0-100)
148
- * @returns A new object with the same structure but localized string values
149
- */
150
- async localizeObject(obj, params, progressCallback) {
151
- return this._localizeRaw(obj, params, void 0, progressCallback);
152
- }
153
- /**
154
- * Localize a single text string
155
- * @param text - The text string to be localized
156
- * @param params - Localization parameters:
157
- * - sourceLocale: The source language code (e.g., 'en')
158
- * - targetLocale: The target language code (e.g., 'es')
159
- * - fast: Optional boolean to enable fast mode (faster for bigger batches)
160
- * @param progressCallback - Optional callback function to report progress (0-100)
161
- * @returns The localized text string
162
- */
163
- async localizeText(text, params, progressCallback) {
164
- const response = await this._localizeRaw({ text }, params, void 0, progressCallback);
165
- return response.text || "";
166
- }
167
- /**
168
- * Localize a text string to multiple target locales
169
- * @param text - The text string to be localized
170
- * @param params - Localization parameters:
171
- * - sourceLocale: The source language code (e.g., 'en')
172
- * - targetLocales: An array of target language codes (e.g., ['es', 'fr'])
173
- * - fast: Optional boolean to enable fast mode (for bigger batches)
174
- * @returns An array of localized text strings
175
- */
176
- async batchLocalizeText(text, params) {
177
- const responses = await Promise.all(
178
- params.targetLocales.map(
179
- (targetLocale) => this.localizeText(text, {
180
- sourceLocale: params.sourceLocale,
181
- targetLocale,
182
- fast: params.fast
183
- })
184
- )
185
- );
186
- return responses;
187
- }
188
- /**
189
- * Localize a chat sequence while preserving speaker names
190
- * @param chat - Array of chat messages, each with 'name' and 'text' properties
191
- * @param params - Localization parameters:
192
- * - sourceLocale: The source language code (e.g., 'en')
193
- * - targetLocale: The target language code (e.g., 'es')
194
- * - fast: Optional boolean to enable fast mode (faster but potentially lower quality)
195
- * @param progressCallback - Optional callback function to report progress (0-100)
196
- * @returns Array of localized chat messages with preserved structure
197
- */
198
- async localizeChat(chat, params, progressCallback) {
199
- const localized = await this._localizeRaw({ chat }, params, void 0, progressCallback);
200
- return Object.entries(localized).map(([key, value]) => ({
201
- name: chat[parseInt(key.split("_")[1])].name,
202
- text: value
203
- }));
204
- }
205
- /**
206
- * Localize an HTML document while preserving structure and formatting
207
- * Handles both text content and localizable attributes (alt, title, placeholder, meta content)
208
- * @param html - The HTML document string to be localized
209
- * @param params - Localization parameters:
210
- * - sourceLocale: The source language code (e.g., 'en')
211
- * - targetLocale: The target language code (e.g., 'es')
212
- * - fast: Optional boolean to enable fast mode (faster but potentially lower quality)
213
- * @param progressCallback - Optional callback function to report progress (0-100)
214
- * @returns The localized HTML document as a string, with updated lang attribute
215
- */
216
- async localizeHtml(html, params, progressCallback) {
217
- const jsdomPackage = await import("jsdom");
218
- const { JSDOM } = jsdomPackage;
219
- const dom = new JSDOM(html);
220
- const document = dom.window.document;
221
- const LOCALIZABLE_ATTRIBUTES = {
222
- meta: ["content"],
223
- img: ["alt"],
224
- input: ["placeholder"],
225
- a: ["title"]
226
- };
227
- const UNLOCALIZABLE_TAGS = ["script", "style"];
228
- const extractedContent = {};
229
- const getPath = (node, attribute) => {
230
- const indices = [];
231
- let current = node;
232
- let rootParent = "";
233
- while (current) {
234
- const parent = current.parentElement;
235
- if (!parent) break;
236
- if (parent === document.documentElement) {
237
- rootParent = current.nodeName.toLowerCase();
238
- break;
239
- }
240
- const siblings = Array.from(parent.childNodes).filter(
241
- (n) => n.nodeType === 1 || n.nodeType === 3 && n.textContent?.trim()
242
- );
243
- const index = siblings.indexOf(current);
244
- if (index !== -1) {
245
- indices.unshift(index);
246
- }
247
- current = parent;
248
- }
249
- const basePath = rootParent ? `${rootParent}/${indices.join("/")}` : indices.join("/");
250
- return attribute ? `${basePath}#${attribute}` : basePath;
251
- };
252
- const processNode = (node) => {
253
- let parent = node.parentElement;
254
- while (parent) {
255
- if (UNLOCALIZABLE_TAGS.includes(parent.tagName.toLowerCase())) {
256
- return;
257
- }
258
- parent = parent.parentElement;
259
- }
260
- if (node.nodeType === 3) {
261
- const text = node.textContent?.trim() || "";
262
- if (text) {
263
- extractedContent[getPath(node)] = text;
264
- }
265
- } else if (node.nodeType === 1) {
266
- const element = node;
267
- const tagName = element.tagName.toLowerCase();
268
- const attributes = LOCALIZABLE_ATTRIBUTES[tagName] || [];
269
- attributes.forEach((attr) => {
270
- const value = element.getAttribute(attr);
271
- if (value) {
272
- extractedContent[getPath(element, attr)] = value;
273
- }
274
- });
275
- Array.from(element.childNodes).filter((n) => n.nodeType === 1 || n.nodeType === 3 && n.textContent?.trim()).forEach(processNode);
276
- }
277
- };
278
- Array.from(document.head.childNodes).filter((n) => n.nodeType === 1 || n.nodeType === 3 && n.textContent?.trim()).forEach(processNode);
279
- Array.from(document.body.childNodes).filter((n) => n.nodeType === 1 || n.nodeType === 3 && n.textContent?.trim()).forEach(processNode);
280
- const localizedContent = await this._localizeRaw(extractedContent, params, void 0, progressCallback);
281
- document.documentElement.setAttribute("lang", params.targetLocale);
282
- Object.entries(localizedContent).forEach(([path, value]) => {
283
- const [nodePath, attribute] = path.split("#");
284
- const [rootTag, ...indices] = nodePath.split("/");
285
- let parent = rootTag === "head" ? document.head : document.body;
286
- let current = parent;
287
- for (const index of indices) {
288
- const siblings = Array.from(parent.childNodes).filter(
289
- (n) => n.nodeType === 1 || n.nodeType === 3 && n.textContent?.trim()
290
- );
291
- current = siblings[parseInt(index)] || null;
292
- if (current?.nodeType === 1) {
293
- parent = current;
294
- }
295
- }
296
- if (current) {
297
- if (attribute) {
298
- current.setAttribute(attribute, value);
299
- } else {
300
- current.textContent = value;
301
- }
302
- }
303
- });
304
- return dom.serialize();
305
- }
306
- /**
307
- * Detect the language of a given text
308
- * @param text - The text to analyze
309
- * @returns Promise resolving to a locale code (e.g., 'en', 'es', 'fr')
310
- */
311
- async recognizeLocale(text) {
312
- const response = await fetch(`${this.config.apiUrl}/recognize`, {
313
- method: "POST",
314
- headers: {
315
- "Content-Type": "application/json",
316
- Authorization: `Bearer ${this.config.apiKey}`
317
- },
318
- body: JSON.stringify({ text })
319
- });
320
- if (!response.ok) {
321
- throw new Error(`Error recognizing locale: ${response.statusText}`);
322
- }
323
- const jsonResponse = await response.json();
324
- return jsonResponse.locale;
325
- }
326
- };
327
-
328
- export {
329
- ReplexicaEngine
330
- };
331
- //# sourceMappingURL=chunk-XU7ZJKQ2.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../sdk/build/index.mjs"],"sourcesContent":["// src/index.ts\nimport Z from \"zod\";\nimport { localeCodeSchema } from \"@lingo.dev/_spec\";\nimport { createId } from \"@paralleldrive/cuid2\";\nvar engineParamsSchema = Z.object({\n apiKey: Z.string(),\n apiUrl: Z.string().url().default(\"https://engine.lingo.dev\"),\n batchSize: Z.number().int().gt(0).lte(250).default(25),\n idealBatchItemSize: Z.number().int().gt(0).lte(2500).default(250)\n}).passthrough();\nvar payloadSchema = Z.record(Z.string(), Z.any());\nvar localizationParamsSchema = Z.object({\n sourceLocale: localeCodeSchema,\n targetLocale: localeCodeSchema,\n fast: Z.boolean().optional()\n});\nvar referenceSchema = Z.record(localeCodeSchema, payloadSchema);\nvar ReplexicaEngine = class {\n config;\n /**\n * Create a new ReplexicaEngine instance\n * @param config - Configuration options for the Engine\n */\n constructor(config) {\n this.config = engineParamsSchema.parse(config);\n }\n /**\n * Localize content using the Lingo.dev API\n * @param payload - The content to be localized\n * @param params - Localization parameters including source/target locales and fast mode option\n * @param reference - Optional reference translations to maintain consistency\n * @param progressCallback - Optional callback function to report progress (0-100)\n * @returns Localized content\n * @internal\n */\n async _localizeRaw(payload, params, reference, progressCallback) {\n const finalPayload = payloadSchema.parse(payload);\n const finalParams = localizationParamsSchema.parse(params);\n const chunkedPayload = this.extractPayloadChunks(finalPayload);\n const processedPayloadChunks = [];\n const workflowId = createId();\n for (let i = 0; i < chunkedPayload.length; i++) {\n const chunk = chunkedPayload[i];\n const percentageCompleted = Math.round((i + 1) / chunkedPayload.length * 100);\n const processedPayloadChunk = await this.localizeChunk(\n finalParams.sourceLocale,\n finalParams.targetLocale,\n { data: chunk, reference },\n workflowId,\n params.fast || false\n );\n if (progressCallback) {\n progressCallback(percentageCompleted, chunk, processedPayloadChunk);\n }\n processedPayloadChunks.push(processedPayloadChunk);\n }\n return Object.assign({}, ...processedPayloadChunks);\n }\n /**\n * Localize a single chunk of content\n * @param sourceLocale - Source locale\n * @param targetLocale - Target locale\n * @param payload - Payload containing the chunk to be localized\n * @returns Localized chunk\n */\n async localizeChunk(sourceLocale, targetLocale, payload, workflowId, fast) {\n const res = await fetch(`${this.config.apiUrl}/i18n`, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n Authorization: `Bearer ${this.config.apiKey}`\n },\n body: JSON.stringify(\n {\n params: { workflowId, fast },\n locale: {\n source: sourceLocale,\n target: targetLocale\n },\n data: payload.data,\n reference: payload.reference\n },\n null,\n 2\n )\n });\n if (!res.ok) {\n if (res.status === 400) {\n throw new Error(`Invalid request: ${res.statusText}`);\n } else {\n const errorText = await res.text();\n throw new Error(errorText);\n }\n }\n const jsonResponse = await res.json();\n return jsonResponse.data || {};\n }\n /**\n * Extract payload chunks based on the ideal chunk size\n * @param payload - The payload to be chunked\n * @returns An array of payload chunks\n */\n extractPayloadChunks(payload) {\n const result = [];\n let currentChunk = {};\n let currentChunkItemCount = 0;\n const payloadEntries = Object.entries(payload);\n for (let i = 0; i < payloadEntries.length; i++) {\n const [key, value] = payloadEntries[i];\n currentChunk[key] = value;\n currentChunkItemCount++;\n const currentChunkSize = this.countWordsInRecord(currentChunk);\n if (currentChunkSize > this.config.idealBatchItemSize || currentChunkItemCount >= this.config.batchSize || i === payloadEntries.length - 1) {\n result.push(currentChunk);\n currentChunk = {};\n currentChunkItemCount = 0;\n }\n }\n return result;\n }\n /**\n * Count words in a record or array\n * @param payload - The payload to count words in\n * @returns The total number of words\n */\n countWordsInRecord(payload) {\n if (Array.isArray(payload)) {\n return payload.reduce((acc, item) => acc + this.countWordsInRecord(item), 0);\n } else if (typeof payload === \"object\" && payload !== null) {\n return Object.values(payload).reduce((acc, item) => acc + this.countWordsInRecord(item), 0);\n } else if (typeof payload === \"string\") {\n return payload.trim().split(/\\s+/).filter(Boolean).length;\n } else {\n return 0;\n }\n }\n /**\n * Localize a typical JavaScript object\n * @param obj - The object to be localized (strings will be extracted and translated)\n * @param params - Localization parameters:\n * - sourceLocale: The source language code (e.g., 'en')\n * - targetLocale: The target language code (e.g., 'es')\n * - fast: Optional boolean to enable fast mode (faster but potentially lower quality)\n * @param progressCallback - Optional callback function to report progress (0-100)\n * @returns A new object with the same structure but localized string values\n */\n async localizeObject(obj, params, progressCallback) {\n return this._localizeRaw(obj, params, void 0, progressCallback);\n }\n /**\n * Localize a single text string\n * @param text - The text string to be localized\n * @param params - Localization parameters:\n * - sourceLocale: The source language code (e.g., 'en')\n * - targetLocale: The target language code (e.g., 'es')\n * - fast: Optional boolean to enable fast mode (faster for bigger batches)\n * @param progressCallback - Optional callback function to report progress (0-100)\n * @returns The localized text string\n */\n async localizeText(text, params, progressCallback) {\n const response = await this._localizeRaw({ text }, params, void 0, progressCallback);\n return response.text || \"\";\n }\n /**\n * Localize a text string to multiple target locales\n * @param text - The text string to be localized\n * @param params - Localization parameters:\n * - sourceLocale: The source language code (e.g., 'en')\n * - targetLocales: An array of target language codes (e.g., ['es', 'fr'])\n * - fast: Optional boolean to enable fast mode (for bigger batches)\n * @returns An array of localized text strings\n */\n async batchLocalizeText(text, params) {\n const responses = await Promise.all(\n params.targetLocales.map(\n (targetLocale) => this.localizeText(text, {\n sourceLocale: params.sourceLocale,\n targetLocale,\n fast: params.fast\n })\n )\n );\n return responses;\n }\n /**\n * Localize a chat sequence while preserving speaker names\n * @param chat - Array of chat messages, each with 'name' and 'text' properties\n * @param params - Localization parameters:\n * - sourceLocale: The source language code (e.g., 'en')\n * - targetLocale: The target language code (e.g., 'es')\n * - fast: Optional boolean to enable fast mode (faster but potentially lower quality)\n * @param progressCallback - Optional callback function to report progress (0-100)\n * @returns Array of localized chat messages with preserved structure\n */\n async localizeChat(chat, params, progressCallback) {\n const localized = await this._localizeRaw({ chat }, params, void 0, progressCallback);\n return Object.entries(localized).map(([key, value]) => ({\n name: chat[parseInt(key.split(\"_\")[1])].name,\n text: value\n }));\n }\n /**\n * Localize an HTML document while preserving structure and formatting\n * Handles both text content and localizable attributes (alt, title, placeholder, meta content)\n * @param html - The HTML document string to be localized\n * @param params - Localization parameters:\n * - sourceLocale: The source language code (e.g., 'en')\n * - targetLocale: The target language code (e.g., 'es')\n * - fast: Optional boolean to enable fast mode (faster but potentially lower quality)\n * @param progressCallback - Optional callback function to report progress (0-100)\n * @returns The localized HTML document as a string, with updated lang attribute\n */\n async localizeHtml(html, params, progressCallback) {\n const jsdomPackage = await import(\"jsdom\");\n const { JSDOM } = jsdomPackage;\n const dom = new JSDOM(html);\n const document = dom.window.document;\n const LOCALIZABLE_ATTRIBUTES = {\n meta: [\"content\"],\n img: [\"alt\"],\n input: [\"placeholder\"],\n a: [\"title\"]\n };\n const UNLOCALIZABLE_TAGS = [\"script\", \"style\"];\n const extractedContent = {};\n const getPath = (node, attribute) => {\n const indices = [];\n let current = node;\n let rootParent = \"\";\n while (current) {\n const parent = current.parentElement;\n if (!parent) break;\n if (parent === document.documentElement) {\n rootParent = current.nodeName.toLowerCase();\n break;\n }\n const siblings = Array.from(parent.childNodes).filter(\n (n) => n.nodeType === 1 || n.nodeType === 3 && n.textContent?.trim()\n );\n const index = siblings.indexOf(current);\n if (index !== -1) {\n indices.unshift(index);\n }\n current = parent;\n }\n const basePath = rootParent ? `${rootParent}/${indices.join(\"/\")}` : indices.join(\"/\");\n return attribute ? `${basePath}#${attribute}` : basePath;\n };\n const processNode = (node) => {\n let parent = node.parentElement;\n while (parent) {\n if (UNLOCALIZABLE_TAGS.includes(parent.tagName.toLowerCase())) {\n return;\n }\n parent = parent.parentElement;\n }\n if (node.nodeType === 3) {\n const text = node.textContent?.trim() || \"\";\n if (text) {\n extractedContent[getPath(node)] = text;\n }\n } else if (node.nodeType === 1) {\n const element = node;\n const tagName = element.tagName.toLowerCase();\n const attributes = LOCALIZABLE_ATTRIBUTES[tagName] || [];\n attributes.forEach((attr) => {\n const value = element.getAttribute(attr);\n if (value) {\n extractedContent[getPath(element, attr)] = value;\n }\n });\n Array.from(element.childNodes).filter((n) => n.nodeType === 1 || n.nodeType === 3 && n.textContent?.trim()).forEach(processNode);\n }\n };\n Array.from(document.head.childNodes).filter((n) => n.nodeType === 1 || n.nodeType === 3 && n.textContent?.trim()).forEach(processNode);\n Array.from(document.body.childNodes).filter((n) => n.nodeType === 1 || n.nodeType === 3 && n.textContent?.trim()).forEach(processNode);\n const localizedContent = await this._localizeRaw(extractedContent, params, void 0, progressCallback);\n document.documentElement.setAttribute(\"lang\", params.targetLocale);\n Object.entries(localizedContent).forEach(([path, value]) => {\n const [nodePath, attribute] = path.split(\"#\");\n const [rootTag, ...indices] = nodePath.split(\"/\");\n let parent = rootTag === \"head\" ? document.head : document.body;\n let current = parent;\n for (const index of indices) {\n const siblings = Array.from(parent.childNodes).filter(\n (n) => n.nodeType === 1 || n.nodeType === 3 && n.textContent?.trim()\n );\n current = siblings[parseInt(index)] || null;\n if (current?.nodeType === 1) {\n parent = current;\n }\n }\n if (current) {\n if (attribute) {\n current.setAttribute(attribute, value);\n } else {\n current.textContent = value;\n }\n }\n });\n return dom.serialize();\n }\n /**\n * Detect the language of a given text\n * @param text - The text to analyze\n * @returns Promise resolving to a locale code (e.g., 'en', 'es', 'fr')\n */\n async recognizeLocale(text) {\n const response = await fetch(`${this.config.apiUrl}/recognize`, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n Authorization: `Bearer ${this.config.apiKey}`\n },\n body: JSON.stringify({ text })\n });\n if (!response.ok) {\n throw new Error(`Error recognizing locale: ${response.statusText}`);\n }\n const jsonResponse = await response.json();\n return jsonResponse.locale;\n }\n};\nexport {\n ReplexicaEngine\n};\n"],"mappings":";;;;;AACA,OAAO,OAAO;AAEd,SAAS,gBAAgB;AACzB,IAAI,qBAAqB,EAAE,OAAO;AAAA,EAChC,QAAQ,EAAE,OAAO;AAAA,EACjB,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,0BAA0B;AAAA,EAC3D,WAAW,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,CAAC,EAAE,IAAI,GAAG,EAAE,QAAQ,EAAE;AAAA,EACrD,oBAAoB,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,CAAC,EAAE,IAAI,IAAI,EAAE,QAAQ,GAAG;AAClE,CAAC,EAAE,YAAY;AACf,IAAI,gBAAgB,EAAE,OAAO,EAAE,OAAO,GAAG,EAAE,IAAI,CAAC;AAChD,IAAI,2BAA2B,EAAE,OAAO;AAAA,EACtC,cAAc;AAAA,EACd,cAAc;AAAA,EACd,MAAM,EAAE,QAAQ,EAAE,SAAS;AAC7B,CAAC;AACD,IAAI,kBAAkB,EAAE,OAAO,kBAAkB,aAAa;AAC9D,IAAI,kBAAkB,MAAM;AAAA,EAC1B;AAAA;AAAA;AAAA;AAAA;AAAA,EAKA,YAAY,QAAQ;AAClB,SAAK,SAAS,mBAAmB,MAAM,MAAM;AAAA,EAC/C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,MAAM,aAAa,SAAS,QAAQ,WAAW,kBAAkB;AAC/D,UAAM,eAAe,cAAc,MAAM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