Skip to content

Latest commit

 

History

History
704 lines (521 loc) · 25.7 KB

api-client-reference.md

File metadata and controls

704 lines (521 loc) · 25.7 KB

API Client Reference

Table of Contents

Setup

Create a new instance of ApiClient and pass in your project token.

Arguments Type Description
options ApiClientOptions Api client options.
Returns Type
ApiClient ApiClient
import { ApiClient } from '@localazy/api-client';

const api = new ApiClient({ authToken: 'project-token' });

Projects

projects.list(request[, config])

List all projects.

See: Localazy API Docs

Arguments Type Description
request ProjectsListRequest Projects list request config.
config optional RequestConfig Request config.
Returns Type
Promise<Project[]> Project
const projects = await api.projects.list({
  organization: true,
  languages: true,
});

projects.first(request[, config])

First project.

At least one project must exist, otherwise an error is thrown.

See: Localazy API Docs

Arguments Type Description
request ProjectsListRequest Projects list request config.
config optional RequestConfig Request config.
Returns Type
Promise<Project> Project
const project = await api.projects.first({
  organization: true,
  languages: true,
});

Files

files.list(request[, config])

List all files in the project.

See: Localazy API Docs

Arguments Type
request FilesListRequest
config optional RequestConfig
Returns Type
Promise<File[]> File
const files = await api.files.list({
  project: 'project-id', // or Project object
});

files.first(request[, config])

First file in the project.

At least one file must exist, otherwise an error is thrown.

See: Localazy API Docs

Arguments Type
request FilesListRequest
config optional RequestConfig
Returns Type
Promise<File> File
const file = await api.files.first({
  project: 'project-id', // or Project object
});

files.listKeys(request[, config])

List all keys for the language in the file.

See: Localazy API Docs

Arguments Type
request FileListKeysRequest
config optional RequestConfig
Returns Type
Promise<Key[]> Key
import { Locales } from '@localazy/api-client';

const keys = await api.files.listKeys({
  project: 'project-id', // or Project object
  file: 'file-id', // or File object
  lang: Locales.ENGLISH,
});

files.listKeysPage(request[, config])

List all keys for the language in the file. Result is paginated.

See: Localazy API Docs

Arguments Type
request FileListKeysRequest
config optional RequestConfig
Returns Type
Promise<PaginatedKeys> PaginatedKeys
import { Locales } from '@localazy/api-client';

const keys = [];
let pageResult = { keys: [], next: '' };

do {
  pageResult = await api.files.listKeysPage({
    project: 'project-id', // or Project object
    file: 'file-id', // or File object
    lang: Locales.ENGLISH,
    next: pageResult.next,
  });
  keys.push(...pageResult.keys);
} while (pageResult.next);

files.getContents(request[, config])

Get the contents of the file.

See: Localazy API Docs

Arguments Type
request FileGetContentRequest
config optional RequestConfig
Returns Type
Promise<Blob> Blob
import { Locales } from '@localazy/api-client';

const blob = await api.files.getContents({
  project: 'project-id', // or Project object
  file: 'file-id', // or File object
  lang: Locales.ENGLISH,
});

Keys

keys.update(request[, config])

Update key.

See: Localazy API Docs

Arguments Type
request KeyUpdateRequest
config optional RequestConfig
Returns
Promise<void>
await api.keys.update({
  project: 'project-id', // or Project object
  key: 'key-id', // or Key object
  deprecated: -1,
  hidden: false,
  comment: 'Comment.',
  limit: -1,
});

keys.delete(request[, config])

Delete key.

See: Localazy API Docs

Arguments Type
request KeyDeleteRequest
config optional RequestConfig
Returns
Promise<void>
await api.keys.delete({
  project: 'project-id', // or Project object
  key: 'key-id', // or Key object
});

Import

import.json(request[, config])

Import JSON object as source keys.

See: Localazy API Docs

Arguments Type
request ImportJsonRequest
config optional RequestConfig
Returns Type
Promise<File> File
import { I18nDeprecate } from '@localazy/api-client';

const json = { en: { headers: { name: 'Name' } } };

const file = await api.import.json({
  project: 'project-id', // or Project object
  json,
  i18nOptions: {
    importAsNew: false,
    forceCurrent: false,
    forceSource: false,
    filterSource: true,
    deprecate: I18nDeprecate.NONE,
  },
  fileOptions: {
    name: 'translations.json',
    path: 'path/to/dir',
    module: 'i18n',
    buildType: '',
    productFlavors: [],
  },
});

Export

export.json(request[, config])

Export translated keys as JSON object.

Arguments Type
request ExportJsonRequest
config optional RequestConfig
Returns Type
Promise<I18nJson> I18nJson
import { Locales } from '@localazy/api-client';

const json = await api.export.json({
  project: 'project-id', // or Project object
  file: 'file-id', // or File object
  langs: [Locales.ENGLISH],
});

Formats

formats.list([config])

List all formats and related options.

See: Localazy API Docs

Arguments Type
config optional RequestConfig
Returns Type
Promise<Format[]> Format
const formats = await api.formats.list();

Screenshots

screenshots.list(request[, config])

List all screenshots in the project.

See: Localazy API Docs

Arguments Type
request ScreenshotsListRequest
config optional RequestConfig
Returns Type
Promise<Screenshot[]> Screenshot
const screenshots = await api.screenshots.list({
  project: 'project-id', // or Project object
});

screenshots.listTags(request[, config])

List all screenshots tags in the project.

See: Localazy API Docs

Arguments Type
request ScreenshotsListTagsRequest
config optional RequestConfig
Returns Type
Promise<ScreenshotTag[]> ScreenshotTag
const tags = await api.screenshots.listTags({
  project: 'project-id', // or Project object
});

screenshots.create(request[, config])

Create screenshot.

See: Localazy API Docs

Arguments Type
request ScreenshotCreateRequest
config optional RequestConfig
Returns Type
Promise<string> Screenshot id.
const id = await api.screenshots.create({
  project: 'project-id', // or Project object
  encodedData: 'data:image/jpg;base64,...',
});

screenshots.updateImageData(request[, config])

Update the image data of screenshot.

See: Localazy API Docs

Arguments Type
request ScreenshotUpdateImageDataRequest
config optional RequestConfig
Returns
Promise<void>
await api.screenshots.updateImageData({
  project: 'project-id', // or Project object
  encodedData: 'data:image/jpg;base64,...',
});

screenshots.update(request[, config])

Update screenshot. Image data are updated with screenshots.updateImageData.

See: Localazy API Docs

Arguments Type
request ScreenshotUpdateRequest
config optional RequestConfig
Returns
Promise<void>
await api.screenshots.update({
  project: 'project-id', // or Project object
  screenshot: 'screenshot-id', // or Screenshot object
  comment: 'Customers list.',
  tags: ['customers'],
});

screenshots.delete(request[, config])

Delete screenshot.

See: Localazy API Docs

Arguments Type
request ScreenshotDeleteRequest
config optional RequestConfig
Returns
Promise<void>
await api.screenshots.delete({
  project: 'project-id', // or Project object
  screenshot: 'screenshot-id', // or Screenshot object
});

Glossary

glossary.list(request[, config])

List all glossary records in the project.

See: Localazy API Docs

Arguments Type
request GlossaryListRequest
config optional RequestConfig
Returns Type
Promise<GlossaryRecord[]> GlossaryRecord
const glossaryRecords = await api.glossary.list({
  project: 'project-id', // or Project object
});

glossary.find(request[, config])

Find glossary record specified by id.

See: Localazy API Docs

Arguments Type
request GlossaryFindRequest
config optional RequestConfig
Returns Type
Promise<GlossaryRecord> GlossaryRecord
const glossaryRecord = await api.glossary.find({
  project: 'project-id', // or Project object
  glossaryRecord: 'glossary-record-id', // or GlossaryRecord object
});

glossary.create(request[, config])

Create glossary record.

See: Localazy API Docs

Arguments Type
request GlossaryCreateRequest
config optional RequestConfig
Returns Type
Promise<string> GlossaryRecord id.
import { Locales } from '@localazy/api-client';

const id = await api.glossary.create({
  project: 'project-id', // or Project object
  description: 'Term description',
  caseSensitive: true,
  translateTerm: true,
  term: [{ lang: Locales.ENGLISH, term: 'befitting' }],
});

glossary.update(request[, config])

Update glossary record specified by id.

See: Localazy API Docs

Arguments Type
request GlossaryUpdateRequest
config optional RequestConfig
Returns
Promise<void>
import { Locales } from '@localazy/api-client';

await api.glossary.update({
  project: 'project-id', // or Project object
  glossaryRecord: 'glossary-record-id', // or GlossaryRecord object
  description: 'Term description',
  caseSensitive: true,
  translateTerm: true,
  term: [{ lang: Locales.ENGLISH, term: 'befitting' }],
});

glossary.delete(request[, config])

Delete glossary record specified by id.

See: Localazy API Docs

Arguments Type
request GlossaryDeleteRequest
config optional RequestConfig
Returns
Promise<void>
await api.glossary.delete({
  project: 'project-id', // or Project object
  glossaryRecord: 'glossary-record-id', // or GlossaryRecord object
});

Webhooks

webhooks.list(request[, config])

List all webhooks in the project.

See: Localazy API Docs

Arguments Type
request WebhooksListRequest
config optional RequestConfig
Returns Type
Promise<Webhook[]> Webhook
const webhooks = await api.webhooks.list({
  project: 'project-id', // or Project object
});

webhooks.update(request[, config])

Update all webhooks in the project.

See: Localazy API Docs

Arguments Type
request WebhooksUpdateRequest
config optional RequestConfig
Returns
Promise<void>
await api.webhooks.update({
  project: 'project-id', // or Project object
  data: [
    {
      enabled: true,
      customId: '1',
      description: 'This is a test webhook',
      url: 'https://example.com/webhook',
      events: ['comment_added', 'import_finished', 'import_finished_empty', 'project_published', 'tag_promoted'],
    },
  ],
});

webhooks.getSecret(request[, config])

Get secret for webhooks in the project. Localazy signs the webhook events it sends to your endpoints and adds a signature in the request header https://localazy.com/docs/api/webhooks-api#security.

See: Localazy API Docs

Arguments Type
request WebhooksGetSecretRequest
config optional RequestConfig
Returns Type
Promise<WebhooksSecret> WebhooksSecret
const secret = await api.webhooks.getSecret({
  project: 'project-id', // or Project object
});