@lokalise/tm-sdk
TypeScript icon, indicating that this package has built-in type declarations

2.2.0 • Public • Published

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.

Readme

Keywords

none

Package Sidebar

Install

npm i @lokalise/tm-sdk

Weekly Downloads

359

Version

2.2.0

License

Apache-2.0

Unpacked Size

22.6 kB

Total Files

20

Last publish

Collaborators

  • carlos_gamero
  • kibertoad
  • arthuracs
  • yury.kravtsov
  • filippos.mikropoulos
  • aplokalise
  • botlokalise
  • laurislokalise
  • marcocardosolok
  • bodrovis