13.2.0 • Published 8 months ago

@lokalise/polyglot-sdk v13.2.0

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
8 months ago

Polyglot Client SDK

Polyglot service provides a REST API to interact with it directly, but we recommend using this @lokalise/polyglot-sdk NPM package to integrate Translation and LQA capabilities into your Node.js application.

Usage

Use the following command to add the package to your project:

npm install @lokalise/polyglot-sdk

After that, you can start using the SDK like this:

import { PolyglotClient } from '@lokalise/polyglot-sdk'

const client = new PolyglotClient({
	// Polyglot instance URL
	baseUrl: 'e.g. https://polyglot-service-main.test.lokalise.cloud',
	// Authentication token in JWT format
	jwtToken: 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.ey...',
	// Optional Undici retry config (see RetryConfig in https://github.com/kibertoad/undici-retry)
	retryConfig: {},
	logger,
})

Translate

To translate some content units asynchronously, you can use a following call example:

const reqContext: RequestContext

// Either<Error, 'scheduled' | 'nothingToTranslate'>
const polyglotResponse = await this.polyglotClient.translateAsync(
	{
		sourceLocale: 'en',
		targetLocale: 'de',
		contentUnits: [
			{
				id: '018f5231-7be5-b816-116b-4b0426d0f428',
				segments: [
					{
						id: '018f5231-d61d-aec6-c6b2-ed676bbab868',
						value: 'Hello world',
					},
				],
			},
		],
		tenantId: 'autopilot',
		ownerId: '<unique_project_id>',
		originCorrelationId: '<unique_job_id',
		callbackUrl: 'https://<callback_url_on_consumer_side>',
		callbackToken: '<auth_token_that_will_be_passed_within_callback>',
	},
	{ reqContext, fakeProcessing: false },
)

If polyglotResponse is 'scheduled', that means the request was put into the Polyglot queue and after it is processed, Polyglot will call given callbackUrl and provide the results (see Callback section for details).

Results callback will have the following structure:

// POST <callbackUrl>
// Authorization: Bearer <callbackToken>

{
	"originCorrelationId": "018f3958-a3bb-05cc-2243-58976a74cd35#1",
	"data": [
		{
			"contentUnitId": "018f3414-7070-e998-3628-5ab485306760",
			"segmentId": "018f3414-7070-e998-3628-5ab485306761",
			"polyglotRefId": "fc9d0719-4470-4756-a655-be925c2b56e8",
			"integration": "ChatGPT-4",
			"translation": "mundo",
			"score": 0.88
		},
		{
			"contentUnitId": "018f3414-7070-e998-3628-5ab485306760",
			"segmentId": "018f3414-7070-e998-3628-5ab485306762",
			"polyglotRefId": "403f65d3-81ab-4204-8bda-4860f08c5258",
			"integration": "ChatGPT-4",
			"translation": "hola",
			"score": null
		}
	]
}

See https://lokalise.atlassian.net/wiki/spaces/PDE/pages/2787180586/Polyglot+APIs+and+Usage+guidelines#Translate-API-(async) for more details on available parameters and results.

LQA

TBD after async endpoint is implemented

13.2.0

8 months ago

13.1.1

9 months ago

13.1.2

9 months ago

13.1.0

9 months ago

12.6.0

9 months ago

13.0.0

9 months ago

12.7.0

9 months ago

12.5.0

9 months ago

12.4.1

9 months ago

12.4.0

9 months ago

12.3.0

10 months ago

12.3.1

10 months ago

12.2.0

10 months ago

12.1.0

10 months ago

12.0.1

10 months ago

12.0.0

11 months ago

5.6.0

1 year ago

5.5.0

1 year ago

5.4.1

1 year ago

5.4.0

1 year ago

5.3.0

1 year ago

5.2.0

1 year ago

5.1.0

1 year ago

6.1.0

1 year ago

6.0.1

1 year ago

10.0.0

12 months ago

6.0.0

1 year ago

10.1.0

12 months ago

10.2.0

11 months ago

7.0.0

12 months ago

8.0.1

12 months ago

8.0.0

12 months ago

9.1.0

12 months ago

9.0.0

12 months ago

11.0.0

11 months ago

5.6.1

1 year ago

5.0.0

1 year ago

4.4.0

1 year ago

4.3.1

1 year ago

4.3.0

1 year ago

4.2.0

1 year ago

4.1.1

1 year ago

4.1.0

1 year ago

4.0.1

1 year ago

4.0.0

1 year ago

4.0.2

1 year ago

3.4.0

1 year ago

3.3.0

1 year ago

3.2.0

1 year ago

3.1.0

1 year ago

3.0.0

1 year ago

2.1.0

1 year ago

2.0.0

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago