@lokalise/tm-sdk 1.1.0 → 2.0.1
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
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# Translation Memory client SDK
|
|
2
|
+
|
|
3
|
+
Translation Memory service provides a REST API to interact with it, but we recommend using this [@lokalise/tm-sdk](https://www.npmjs.com/package/@lokalise/tm-sdk) NPM package to integrate TM capabilities into your Node.js application.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
Use the following command to add the package to your project:
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
npm install @lokalise/tm-sdk
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
After that, you can start using the SDK like this:
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import { TranslationMemoryClient } from '@lokalise/tm-sdk'
|
|
17
|
+
|
|
18
|
+
const client = new TranslationMemoryClient({
|
|
19
|
+
isEnabled: true,
|
|
20
|
+
baseUrl: 'https://<tm-service-server-url>',
|
|
21
|
+
jwtToken: '<JWT auth token provided by the TM service>',
|
|
22
|
+
// Undici retry config (see RetryConfig in https://github.com/kibertoad/undici-retry)
|
|
23
|
+
retryConfig: {},
|
|
24
|
+
// See types in https://github.com/lokalise/node-core/blob/main/src/errors/errorReporterTypes.ts
|
|
25
|
+
errorReporter: {
|
|
26
|
+
report: (errorReport: ErrorReport) => {},
|
|
27
|
+
},
|
|
28
|
+
})
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
To create new records, call `upsertRecords()` method:
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
const records = [
|
|
35
|
+
{
|
|
36
|
+
ownerId: '018dac6e-bff7-689a-f0ba-e84f49c5e432',
|
|
37
|
+
sourceLocale: 'en',
|
|
38
|
+
targetLocale: 'de',
|
|
39
|
+
sourcePrevContent: 'Localization meets AI',
|
|
40
|
+
sourceText: 'Your one-stop solution for AI-powered translations.',
|
|
41
|
+
targetText: 'Ihre Lösung aus einer Hand für KI-gestützte Übersetzungen.',
|
|
42
|
+
sourceNextContent:
|
|
43
|
+
'Save money, speed up your market entry, and charm customers in every language.',
|
|
44
|
+
},
|
|
45
|
+
]
|
|
46
|
+
client.upsertRecords('my-tm-group', records)
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
To search for exact matching records, you can use `findMatches()` API.
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
const searchRequest = {
|
|
53
|
+
sourceText: 'Your one-stop solution for AI-powered translations and automated localization.',
|
|
54
|
+
sourceLocale: 'en',
|
|
55
|
+
targetLocale: 'de',
|
|
56
|
+
prevContent: 'Localization meets AI',
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* [{
|
|
60
|
+
* sourceText: 'Your one-stop solution for AI-powered translations.'
|
|
61
|
+
* targetText: 'Ihre Lösung aus einer Hand für KI-gestützte Übersetzungen.'
|
|
62
|
+
* }]
|
|
63
|
+
*/
|
|
64
|
+
const matches = client.findMatches('my-tm-group', searchRequest)
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
You can also use `bulkFindMatches()` and `bulkFindMatchesIterative()` APIs to perform the same kind of lookup for multiple separate search requests.
|
|
@@ -19,8 +19,8 @@ export declare class TranslationMemoryClient {
|
|
|
19
19
|
private readonly isEnabled;
|
|
20
20
|
constructor(config: TranslationMemoryClientConfig);
|
|
21
21
|
findMatches(groupId: string, request: FindMatchesRequest): Promise<TranslationMemoryMatch[]>;
|
|
22
|
-
bulkFindMatches(groupId: string,
|
|
23
|
-
bulkFindMatchesIterative(groupId: string,
|
|
22
|
+
bulkFindMatches(groupId: string, { filters, options }: BulkFindMatchesRequest): Promise<BulkTranslationMemoryMatches[]>;
|
|
23
|
+
bulkFindMatchesIterative(groupId: string, { filters, options }: BulkFindMatchesRequest): AsyncGenerator<BulkTranslationMemoryMatches[]>;
|
|
24
24
|
getRecords(groupId: string, pagination?: MandatoryPaginationParams): Promise<TranslationMemoryRecordsResponse>;
|
|
25
25
|
upsertRecords(groupId: string, records: UpsertRecordDto[]): Promise<void>;
|
|
26
26
|
private internalBulkFindMatches;
|
|
@@ -51,17 +51,20 @@ class TranslationMemoryClient {
|
|
|
51
51
|
throw this.handleError(e);
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
|
-
async bulkFindMatches(groupId,
|
|
54
|
+
async bulkFindMatches(groupId, { filters, options }) {
|
|
55
55
|
const response = [];
|
|
56
|
-
for (const
|
|
57
|
-
const partialResponse = await this.internalBulkFindMatches(groupId, {
|
|
56
|
+
for (const part of (0, node_core_1.chunk)(filters, this.maxFindMatchesRequestSize)) {
|
|
57
|
+
const partialResponse = await this.internalBulkFindMatches(groupId, {
|
|
58
|
+
filters: part,
|
|
59
|
+
options,
|
|
60
|
+
});
|
|
58
61
|
response.push(...partialResponse);
|
|
59
62
|
}
|
|
60
63
|
return response;
|
|
61
64
|
}
|
|
62
|
-
async *bulkFindMatchesIterative(groupId,
|
|
63
|
-
for (const
|
|
64
|
-
yield await this.internalBulkFindMatches(groupId, { filters });
|
|
65
|
+
async *bulkFindMatchesIterative(groupId, { filters, options }) {
|
|
66
|
+
for (const part of (0, node_core_1.chunk)(filters, this.maxFindMatchesRequestSize)) {
|
|
67
|
+
yield await this.internalBulkFindMatches(groupId, { filters: part, options });
|
|
65
68
|
}
|
|
66
69
|
}
|
|
67
70
|
async getRecords(groupId, pagination) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TranslationMemoryClient.js","sourceRoot":"","sources":["../../src/sdk/TranslationMemoryClient.ts"],"names":[],"mappings":";;;AAEA,mDAQ4B;AAC5B,gFAAqF;AAIrF,wFAAoF;AAsBpF,MAAa,uBAAuB;IACjB,yBAAyB,GAAG,EAAE,CAAA,CAAC,YAAY;IAE3C,UAAU,CAAQ;IAClB,WAAW,CAAa;IACxB,OAAO,CAAyB;IAChC,aAAa,CAAgB;IAC7B,SAAS,CA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
|
5
5
|
prevContent?: string;
|
|
6
6
|
nextContent?: string;
|
|
7
|
+
};
|
|
8
|
+
export type FindMatchesOptions = {
|
|
7
9
|
maxMatches?: number;
|
|
8
10
|
};
|
|
9
|
-
export type BulkFindMatchesFilter =
|
|
11
|
+
export type BulkFindMatchesFilter = FindMatchesFilter & {
|
|
10
12
|
filterId?: string;
|
|
11
13
|
};
|
|
14
|
+
export type FindMatchesRequest = FindMatchesFilter & FindMatchesOptions;
|
|
12
15
|
export type BulkFindMatchesRequest = {
|
|
13
16
|
filters: BulkFindMatchesFilter[];
|
|
17
|
+
options?: FindMatchesOptions;
|
|
14
18
|
};
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lokalise/tm-sdk",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"author": {
|
|
5
5
|
"name": "Lokalise",
|
|
6
6
|
"url": "https://lokalise.com/"
|
|
7
7
|
},
|
|
8
|
+
"description": "REST API client for the Lokalise Translation Memory service",
|
|
8
9
|
"files": [
|
|
9
10
|
"dist/**"
|
|
10
11
|
],
|
|
@@ -16,6 +17,9 @@
|
|
|
16
17
|
"main": "dist/index.js",
|
|
17
18
|
"types": "dist/index.d.ts",
|
|
18
19
|
"type": "commonjs",
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"access": "public"
|
|
22
|
+
},
|
|
19
23
|
"scripts": {
|
|
20
24
|
"build": "shx rm -rf ./dist && tsc",
|
|
21
25
|
"build:publish": "shx rm -rf ./dist && tsc -p tsconfig.publish.json",
|
|
@@ -24,24 +28,24 @@
|
|
|
24
28
|
"test": "vitest",
|
|
25
29
|
"test:coverage": "npm test -- --coverage",
|
|
26
30
|
"test:ci": "npm run test:coverage",
|
|
27
|
-
"version": "
|
|
31
|
+
"package-version": "echo $npm_package_version",
|
|
28
32
|
"prepublishOnly": "npm run build:publish"
|
|
29
33
|
},
|
|
30
34
|
"dependencies": {
|
|
31
|
-
"@lokalise/api-common": "^
|
|
32
|
-
"@lokalise/
|
|
33
|
-
"
|
|
35
|
+
"@lokalise/api-common": "^3.0.1",
|
|
36
|
+
"@lokalise/id-utils": "^1.0.0",
|
|
37
|
+
"@lokalise/node-core": "^9.10.1",
|
|
38
|
+
"undici": "^6.6.2",
|
|
34
39
|
"undici-retry": "^5.0.2"
|
|
35
40
|
},
|
|
36
41
|
"devDependencies": {
|
|
37
|
-
"@types/node": "20.11.
|
|
38
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
39
|
-
"@typescript-eslint/parser": "^
|
|
40
|
-
"@vitest/coverage-v8": "^1.
|
|
41
|
-
"
|
|
42
|
-
"eslint": "^8.56.0",
|
|
42
|
+
"@types/node": "20.11.20",
|
|
43
|
+
"@typescript-eslint/eslint-plugin": "^7.0.2",
|
|
44
|
+
"@typescript-eslint/parser": "^7.0.2",
|
|
45
|
+
"@vitest/coverage-v8": "^1.3.1",
|
|
46
|
+
"eslint": "^8.57.0",
|
|
43
47
|
"eslint-plugin-import": "^2.29.1",
|
|
44
|
-
"eslint-plugin-vitest": "^0.3.
|
|
48
|
+
"eslint-plugin-vitest": "^0.3.22",
|
|
45
49
|
"mockttp": "^3.10.1",
|
|
46
50
|
"prettier": "^3.2.4",
|
|
47
51
|
"shx": "^0.3.4",
|