@lokalise/polyglot-sdk 4.2.0 → 4.3.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 +111 -0
- package/dist/sdk/types/responses.d.ts +2 -0
- package/package.json +6 -6
package/README.md
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
# Polyglot Client SDK
|
|
2
|
+
|
|
3
|
+
Polyglot service provides a REST API to interact with it directly, but we recommend using
|
|
4
|
+
this [@lokalise/polyglot-sdk](https://www.npmjs.com/package/@lokalise/polyglot-sdk) NPM package to integrate Translation
|
|
5
|
+
and LQA capabilities into your Node.js application.
|
|
6
|
+
|
|
7
|
+
## Usage
|
|
8
|
+
|
|
9
|
+
Use the following command to add the package to your project:
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
npm install @lokalise/polyglot-sdk
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
After that, you can start using the SDK like this:
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import { PolyglotClient } from '@lokalise/polyglot-sdk'
|
|
19
|
+
|
|
20
|
+
const client = new PolyglotClient({
|
|
21
|
+
// Polyglot instance URL
|
|
22
|
+
baseUrl: 'e.g. https://polyglot-service-main.test.lokalise.cloud',
|
|
23
|
+
// Authentication token in JWT format
|
|
24
|
+
jwtToken: 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.ey...',
|
|
25
|
+
// Optional Undici retry config (see RetryConfig in https://github.com/kibertoad/undici-retry)
|
|
26
|
+
retryConfig: {},
|
|
27
|
+
logger,
|
|
28
|
+
})
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### Translate
|
|
32
|
+
|
|
33
|
+
To translate some content units asynchronously, you can use a following call example:
|
|
34
|
+
|
|
35
|
+
```typescript
|
|
36
|
+
const reqContext: RequestContext
|
|
37
|
+
|
|
38
|
+
// Either<Error, 'scheduled' | 'nothingToTranslate'>
|
|
39
|
+
const polyglotResponse = await this.polyglotClient.translateAsync(
|
|
40
|
+
{
|
|
41
|
+
sourceLocale: 'en',
|
|
42
|
+
targetLocale: 'de',
|
|
43
|
+
contentUnits: [
|
|
44
|
+
{
|
|
45
|
+
id: '018f5231-7be5-b816-116b-4b0426d0f428',
|
|
46
|
+
segments: [
|
|
47
|
+
{
|
|
48
|
+
id: '018f5231-d61d-aec6-c6b2-ed676bbab868',
|
|
49
|
+
position: 0,
|
|
50
|
+
value: 'Hello world',
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
},
|
|
54
|
+
],
|
|
55
|
+
tenantId: 'autopilot',
|
|
56
|
+
ownerId: '<unique_project_id>',
|
|
57
|
+
originCorrelationId: '<unique_job_id',
|
|
58
|
+
callbackUrl: 'https://<callback_url_on_consumer_side>',
|
|
59
|
+
callbackToken: '<auth_token_that_will_be_passed_within_callback>',
|
|
60
|
+
},
|
|
61
|
+
{ reqContext, fakeProcessing: false },
|
|
62
|
+
)
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
If `polyglotResponse` is `'scheduled'`, that means the request was put into the Polyglot queue and after it is
|
|
66
|
+
processed, Polyglot will call given `callbackUrl` and provide the results (see Callback section for details).
|
|
67
|
+
|
|
68
|
+
Results callback will have the following structure:
|
|
69
|
+
|
|
70
|
+
```json
|
|
71
|
+
// POST <callbackUrl>
|
|
72
|
+
// Authorization: Bearer <callbackToken>
|
|
73
|
+
|
|
74
|
+
{
|
|
75
|
+
"data": {
|
|
76
|
+
"originCorrelationId": "018f3958-a3bb-05cc-2243-58976a74cd35#1",
|
|
77
|
+
"errors": [],
|
|
78
|
+
"sourceLocale": "en-US",
|
|
79
|
+
"targetLocale": "es",
|
|
80
|
+
"contentUnits": [
|
|
81
|
+
{
|
|
82
|
+
"id": "018f3414-7070-e998-3628-5ab485306760",
|
|
83
|
+
"locale": "es",
|
|
84
|
+
"segments": [
|
|
85
|
+
{
|
|
86
|
+
"id": "018f3414-7070-e998-3628-5ab485306761",
|
|
87
|
+
"position": 0,
|
|
88
|
+
"translation": "mundo",
|
|
89
|
+
"integration": "ChatGPT-4",
|
|
90
|
+
"score": 0.88
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
"id": "018f3414-7070-e998-3628-5ab485306762",
|
|
94
|
+
"position": 1,
|
|
95
|
+
"translation": "hola",
|
|
96
|
+
"integration": "ChatGPT-4",
|
|
97
|
+
"score": null
|
|
98
|
+
}
|
|
99
|
+
]
|
|
100
|
+
}
|
|
101
|
+
]
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
See https://lokalise.atlassian.net/wiki/spaces/PDE/pages/2787180586/Polyglot+APIs+and+Usage+guidelines#Translate-API-(async)
|
|
107
|
+
for more details on available parameters and results.
|
|
108
|
+
|
|
109
|
+
### LQA
|
|
110
|
+
|
|
111
|
+
TBD after async endpoint is implemented
|
|
@@ -27,6 +27,8 @@ export type ContentUnitTranslationResponse = {
|
|
|
27
27
|
position: number;
|
|
28
28
|
translation: string;
|
|
29
29
|
integration: string;
|
|
30
|
+
score?: string | null;
|
|
31
|
+
polyglotRefId?: string;
|
|
30
32
|
}[];
|
|
31
33
|
};
|
|
32
34
|
export type LqaSeverityResponse = 'neutral' | 'minor' | 'major' | 'critical';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lokalise/polyglot-sdk",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.3.0",
|
|
4
4
|
"author": {
|
|
5
5
|
"name": "Lokalise",
|
|
6
6
|
"url": "https://lokalise.com/"
|
|
@@ -33,16 +33,16 @@
|
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@amplitude/analytics-types": "^2.5.0",
|
|
36
|
-
"@lokalise/fastify-extras": "^
|
|
36
|
+
"@lokalise/fastify-extras": "^18.0.0",
|
|
37
37
|
"@lokalise/id-utils": "^1.0.0",
|
|
38
|
-
"@lokalise/node-core": "^9.
|
|
38
|
+
"@lokalise/node-core": "^9.16.0",
|
|
39
39
|
"@lokalise/zod-extras": "^2.0.1",
|
|
40
|
-
"undici": "^6.
|
|
40
|
+
"undici": "^6.15.0",
|
|
41
41
|
"undici-retry": "^5.0.2",
|
|
42
|
-
"zod": "^3.
|
|
42
|
+
"zod": "^3.23.4"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@types/node": "^20.12.
|
|
45
|
+
"@types/node": "^20.12.9",
|
|
46
46
|
"@typescript-eslint/eslint-plugin": "^7.4.0",
|
|
47
47
|
"@typescript-eslint/parser": "^7.4.0",
|
|
48
48
|
"@vitest/coverage-v8": "^0.34.6",
|