REST API client for the Lokalise Translation Memory service
npm install @lokalise/tm-sdkTranslation 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.
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:
`typescript
import { TranslationMemoryClient } from '@lokalise/tm-sdk'
const client = new TranslationMemoryClient({
isEnabled: true,
baseUrl: 'https://
jwtToken: '
// 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:
`typescript
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.
`typescript`
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.