@lokalise/tm-sdk 2.0.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 +67 -0
- package/package.json +15 -12
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.
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lokalise/tm-sdk",
|
|
3
|
-
"version": "2.0.
|
|
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,25 +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": "^
|
|
35
|
+
"@lokalise/api-common": "^3.0.1",
|
|
32
36
|
"@lokalise/id-utils": "^1.0.0",
|
|
33
|
-
"@lokalise/node-core": "^9.
|
|
34
|
-
"undici": "^6.
|
|
37
|
+
"@lokalise/node-core": "^9.10.1",
|
|
38
|
+
"undici": "^6.6.2",
|
|
35
39
|
"undici-retry": "^5.0.2"
|
|
36
40
|
},
|
|
37
41
|
"devDependencies": {
|
|
38
|
-
"@types/node": "20.11.
|
|
39
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
40
|
-
"@typescript-eslint/parser": "^
|
|
41
|
-
"@vitest/coverage-v8": "^1.
|
|
42
|
-
"
|
|
43
|
-
"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",
|
|
44
47
|
"eslint-plugin-import": "^2.29.1",
|
|
45
|
-
"eslint-plugin-vitest": "^0.3.
|
|
48
|
+
"eslint-plugin-vitest": "^0.3.22",
|
|
46
49
|
"mockttp": "^3.10.1",
|
|
47
50
|
"prettier": "^3.2.4",
|
|
48
51
|
"shx": "^0.3.4",
|