@lokalise/tm-sdk
v3.0.0
Published
REST API client for the Lokalise Translation Memory service
Downloads
1,153
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-sdk
After that, you can start using the SDK like this:
import { TranslationMemoryClient } from '@lokalise/tm-sdk'
const client = new TranslationMemoryClient({
isEnabled: true,
baseUrl: 'https://<tm-service-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 records = [
{
ownerId: '018dac6e-bff7-689a-f0ba-e84f49c5e432',
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('my-tm-group', records)
To search for exact matching records, you can use findMatches()
API.
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('my-tm-group', searchRequest)
You can also use bulkFindMatches()
and bulkFindMatchesIterative()
APIs to perform the same kind of lookup for multiple separate search requests.