@lokalise/tm-sdk
v10.3.0
Published
REST API client for the Lokalise Translation Memory service
Maintainers
Keywords
Readme
Translation Memory client SDK
Translation Memory service provides a REST API to interact with it, but we recommend using this @lokalise/tm-sdk NPM package to integrate TM capabilities into your Node.js application.
Usage
Use the following command to add the package to your project:
npm install @lokalise/tm-sdkAfter that, you can start using the SDK like this:
import { TranslationMemoryClient } from '@lokalise/tm-sdk'
const client = new TranslationMemoryClient({
isEnabled: true,
baseUrl: 'https://<translation-memory-server-url>',
jwtToken: '<JWT auth token provided by the TM service>',
// Undici retry config (see RetryConfig in https://github.com/kibertoad/undici-retry)
retryConfig: {},
// See types in https://github.com/lokalise/node-core/blob/main/src/errors/errorReporterTypes.ts
errorReporter: {
report: (errorReport: ErrorReport) => {},
},
})To create new records, call upsertRecords() method:
const requestContext = {
reqId: randomUUID(),
logger: globalLogger,
}
const ownerGroupId = {
ownerId: randomUUID(), // must be UUID
groupId: 'my-group-id'
}
const records = [
{
sourceLocale: 'en',
targetLocale: 'de',
sourcePrevContent: 'Localization meets AI',
sourceText: 'Your one-stop solution for AI-powered translations.',
targetText: 'Ihre Lösung aus einer Hand für KI-gestützte Übersetzungen.',
sourceNextContent:
'Save money, speed up your market entry, and charm customers in every language.',
},
]
client.upsertRecords(requestContext, ownerGroupId, records)To search for exact matching records, you can use findMatches() API.
const requestContext = {
reqId: randomUUID(),
logger: globalLogger,
}
const ownerId = randomUUID()
const searchRequest = {
sourceText: 'Your one-stop solution for AI-powered translations and automated localization.',
sourceLocale: 'en',
targetLocale: 'de',
prevContent: 'Localization meets AI',
}
/**
* [{
* sourceText: 'Your one-stop solution for AI-powered translations.'
* targetText: 'Ihre Lösung aus einer Hand für KI-gestützte Übersetzungen.'
* }]
*/
const matches = client.findMatches(requestContext, ownerId, searchRequest)You can also use bulkFindMatches() and bulkFindMatchesIterative() APIs to perform the same kind of lookup for
multiple separate search requests.
