@translated/lara 1.6.6 → 1.7.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/README.md +26 -0
- package/lib/index.d.ts +1 -1
- package/lib/sdk-version.d.ts +1 -1
- package/lib/sdk-version.js +1 -1
- package/lib/translator/models.d.ts +4 -0
- package/lib/translator/translator.d.ts +3 -2
- package/lib/translator/translator.js +8 -1
- package/lib/utils/toSnakeCase.js +3 -3
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -181,6 +181,32 @@ const options = {
|
|
|
181
181
|
const result = await lara.translate("Hello", "en-US", "fr-FR", options);
|
|
182
182
|
```
|
|
183
183
|
|
|
184
|
+
#### Language Detection
|
|
185
|
+
|
|
186
|
+
Use detect() to automatically identify the language of one or multiple texts.
|
|
187
|
+
|
|
188
|
+
```javascript
|
|
189
|
+
// Single string detection
|
|
190
|
+
const single = await lara.detect("Bonjour tout le monde");
|
|
191
|
+
console.log(single.language); // fr
|
|
192
|
+
|
|
193
|
+
// Multiple strings detection
|
|
194
|
+
const multiple = await lara.detect(["Hello world", "How are you?"]);
|
|
195
|
+
console.log(multiple.languages); // "en"
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
You can provide a hint (expected source language) and a passlist (restrict candidates) to improve accuracy.
|
|
199
|
+
|
|
200
|
+
```javascript
|
|
201
|
+
// Detection with hint and passlist
|
|
202
|
+
const detected = await lara.detect(
|
|
203
|
+
"Es un dÃa soleado",
|
|
204
|
+
"es", // hint (optional)
|
|
205
|
+
["es", "pt", "fr"] // passlist (optional)
|
|
206
|
+
);
|
|
207
|
+
console.log(detected.language); // es
|
|
208
|
+
```
|
|
209
|
+
|
|
184
210
|
### 📖 Document Translation
|
|
185
211
|
#### Simple document translation
|
|
186
212
|
|
package/lib/index.d.ts
CHANGED
|
@@ -2,5 +2,5 @@ export { Credentials } from "./credentials";
|
|
|
2
2
|
export { LaraApiError, LaraError, TimeoutError } from "./errors";
|
|
3
3
|
export { MultiPartFile } from "./net/client";
|
|
4
4
|
export { version } from "./sdk-version";
|
|
5
|
-
export { Document, DocumentDownloadOptions, DocumentStatus, DocumentUploadOptions, Memory, MemoryImport, NGGlossaryMatch, NGMemoryMatch, TextBlock, TextResult } from "./translator/models";
|
|
5
|
+
export { Document, DocumentDownloadOptions, DocumentStatus, DocumentUploadOptions, Memory, MemoryImport, NGGlossaryMatch, NGMemoryMatch, TextBlock, TextResult, DetectResult } from "./translator/models";
|
|
6
6
|
export { Documents, DocumentTranslateOptions, Memories, MemoryImportCallback, TranslateOptions, Translator, TranslatorOptions } from "./translator/translator";
|
package/lib/sdk-version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "1.
|
|
1
|
+
export declare const version = "1.7.0";
|
package/lib/sdk-version.js
CHANGED
|
@@ -83,6 +83,10 @@ export interface TextResult<T extends string | string[] | TextBlock[]> {
|
|
|
83
83
|
readonly adaptedToMatches?: NGMemoryMatch[] | NGMemoryMatch[][];
|
|
84
84
|
readonly glossariesMatches?: NGGlossaryMatch[] | NGGlossaryMatch[][];
|
|
85
85
|
}
|
|
86
|
+
export interface DetectResult {
|
|
87
|
+
language: string;
|
|
88
|
+
contentType: string;
|
|
89
|
+
}
|
|
86
90
|
export interface Glossary {
|
|
87
91
|
readonly id: string;
|
|
88
92
|
readonly name: string;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Credentials } from "../credentials";
|
|
2
2
|
import { type LaraClient } from "../net";
|
|
3
3
|
import type { MultiPartFile } from "../net/client";
|
|
4
|
-
import { type Document, type DocumentDownloadOptions, type DocumentUploadOptions, type Glossary, type GlossaryCounts, type GlossaryImport, type Memory, type MemoryImport, type TextBlock, type TextResult, type TranslationStyle } from "./models";
|
|
4
|
+
import { type DetectResult, type Document, type DocumentDownloadOptions, type DocumentUploadOptions, type Glossary, type GlossaryCounts, type GlossaryImport, type Memory, type MemoryImport, type TextBlock, type TextResult, type TranslationStyle } from "./models";
|
|
5
5
|
export type TranslatorOptions = {
|
|
6
6
|
serverUrl?: string;
|
|
7
7
|
};
|
|
@@ -18,7 +18,7 @@ export declare class Memories {
|
|
|
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
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
|
-
deleteTranslation(id: string | string[], source: string, target: string, sentence
|
|
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>;
|
|
24
24
|
}
|
|
@@ -77,4 +77,5 @@ export declare class Translator {
|
|
|
77
77
|
constructor(credentials: Credentials, options?: TranslatorOptions);
|
|
78
78
|
getLanguages(): Promise<string[]>;
|
|
79
79
|
translate<T extends string | string[] | TextBlock[]>(text: T, source: string | null, target: string, options?: TranslateOptions): Promise<TextResult<T>>;
|
|
80
|
+
detect(text: string | string[], hint?: string, passlist?: string[]): Promise<DetectResult>;
|
|
80
81
|
}
|
|
@@ -7,8 +7,8 @@ exports.Translator = exports.Glossaries = exports.Documents = exports.Memories =
|
|
|
7
7
|
const errors_1 = require("../errors");
|
|
8
8
|
const net_1 = __importDefault(require("../net"));
|
|
9
9
|
const s3_1 = __importDefault(require("../net/s3"));
|
|
10
|
-
const models_1 = require("./models");
|
|
11
10
|
const toSnakeCase_1 = __importDefault(require("../utils/toSnakeCase"));
|
|
11
|
+
const models_1 = require("./models");
|
|
12
12
|
class Memories {
|
|
13
13
|
constructor(client) {
|
|
14
14
|
this.client = client;
|
|
@@ -261,5 +261,12 @@ class Translator {
|
|
|
261
261
|
style: options === null || options === void 0 ? void 0 : options.style
|
|
262
262
|
}, undefined, headers);
|
|
263
263
|
}
|
|
264
|
+
async detect(text, hint, passlist) {
|
|
265
|
+
return await this.client.post("/detect", {
|
|
266
|
+
q: text,
|
|
267
|
+
hint,
|
|
268
|
+
passlist
|
|
269
|
+
});
|
|
270
|
+
}
|
|
264
271
|
}
|
|
265
272
|
exports.Translator = Translator;
|
package/lib/utils/toSnakeCase.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const toSnakeCase = (content) => {
|
|
4
|
-
if (typeof content ===
|
|
4
|
+
if (typeof content === "string")
|
|
5
5
|
return content;
|
|
6
6
|
if (Array.isArray(content))
|
|
7
7
|
return content.map(toSnakeCase);
|
|
8
|
-
if (typeof content ===
|
|
8
|
+
if (typeof content === "object" && content !== null) {
|
|
9
9
|
const result = {};
|
|
10
10
|
for (const [key, value] of Object.entries(content)) {
|
|
11
|
-
const snakeKey = key.replace(/([A-Z])/g,
|
|
11
|
+
const snakeKey = key.replace(/([A-Z])/g, "_$1").toLowerCase();
|
|
12
12
|
result[snakeKey] = toSnakeCase(value);
|
|
13
13
|
}
|
|
14
14
|
return result;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@translated/lara",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.0",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"types": "lib/index.d.ts",
|
|
6
6
|
"engines": {
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
},
|
|
36
36
|
"description": "Official Lara SDK for JavaScript and Node.js",
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"form-data": "^4.0.
|
|
38
|
+
"form-data": "^4.0.4"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@biomejs/biome": "^2.0.6",
|