npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@lokalise/polyglot-sdk

v13.10.0

Published

REST API client for the Lokalise Polyglot service

Downloads

2,800

Readme

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