Skip to content

Latest commit

 

History

History
253 lines (190 loc) · 21.3 KB

File metadata and controls

253 lines (190 loc) · 21.3 KB

Translations.Master

Overview

Available Operations

  • retrieve - Retrieve master translations JSON
  • import - Import master translations JSON
  • upload - Upload master translations JSON file

retrieve

Retrieve all translations for a locale in master JSON format organized by resourceId (workflowId)

Example Usage

import { Novu } from "@novu/api";

const novu = new Novu({
  secretKey: "YOUR_SECRET_KEY_HERE",
});

async function run() {
  const result = await novu.translations.master.retrieve("en_US");

  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { NovuCore } from "@novu/api/core.js";
import { translationsMasterRetrieve } from "@novu/api/funcs/translationsMasterRetrieve.js";

// Use `NovuCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const novu = new NovuCore({
  secretKey: "YOUR_SECRET_KEY_HERE",
});

async function run() {
  const res = await translationsMasterRetrieve(novu, "en_US");
  if (res.ok) {
    const { value: result } = res;
    console.log(result);
  } else {
    console.log("translationsMasterRetrieve failed:", res.error);
  }
}

run();

Parameters

Parameter Type Required Description Example
locale string Locale to export. If not provided, exports organization default locale en_US
idempotencyKey string A header for idempotency purposes
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<components.GetMasterJsonResponseDto>

Errors

Error Type Status Code Content Type
errors.SDKError 4XX, 5XX */*

import

Import translations for multiple workflows from master JSON format for a specific locale

Example Usage

import { Novu } from "@novu/api";

const novu = new Novu({
  secretKey: "YOUR_SECRET_KEY_HERE",
});

async function run() {
  const result = await novu.translations.master.import({
    locale: "en_US",
    masterJson: {
      "workflows": {
        "welcome-email": {
          "welcome.title": "Welcome to our platform",
          "welcome.message": "Hello there!",
        },
        "password-reset": {
          "reset.title": "Reset your password",
          "reset.message": "Click the link to reset",
        },
      },
    },
  });

  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { NovuCore } from "@novu/api/core.js";
import { translationsMasterImport } from "@novu/api/funcs/translationsMasterImport.js";

// Use `NovuCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const novu = new NovuCore({
  secretKey: "YOUR_SECRET_KEY_HERE",
});

async function run() {
  const res = await translationsMasterImport(novu, {
    locale: "en_US",
    masterJson: {
      "workflows": {
        "welcome-email": {
          "welcome.title": "Welcome to our platform",
          "welcome.message": "Hello there!",
        },
        "password-reset": {
          "reset.title": "Reset your password",
          "reset.message": "Click the link to reset",
        },
      },
    },
  });
  if (res.ok) {
    const { value: result } = res;
    console.log(result);
  } else {
    console.log("translationsMasterImport failed:", res.error);
  }
}

run();

Parameters

Parameter Type Required Description
importMasterJsonRequestDto components.ImportMasterJsonRequestDto ✔️ N/A
idempotencyKey string A header for idempotency purposes
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<components.ImportMasterJsonResponseDto>

Errors

Error Type Status Code Content Type
errors.SDKError 4XX, 5XX */*

upload

Upload a master JSON file containing translations for multiple workflows. Locale is automatically detected from filename (e.g., en_US.json)

Example Usage

import { Novu } from "@novu/api";
import { openAsBlob } from "node:fs";

const novu = new Novu({
  secretKey: "YOUR_SECRET_KEY_HERE",
});

async function run() {
  const result = await novu.translations.master.upload({
    file: await openAsBlob("example.file"),
  });

  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { NovuCore } from "@novu/api/core.js";
import { translationsMasterUpload } from "@novu/api/funcs/translationsMasterUpload.js";
import { openAsBlob } from "node:fs";

// Use `NovuCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const novu = new NovuCore({
  secretKey: "YOUR_SECRET_KEY_HERE",
});

async function run() {
  const res = await translationsMasterUpload(novu, {
    file: await openAsBlob("example.file"),
  });
  if (res.ok) {
    const { value: result } = res;
    console.log(result);
  } else {
    console.log("translationsMasterUpload failed:", res.error);
  }
}

run();

Parameters

Parameter Type Required Description
requestBody operations.TranslationControllerUploadMasterJsonEndpointRequestBody ✔️ N/A
idempotencyKey string A header for idempotency purposes
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<components.ImportMasterJsonResponseDto>

Errors

Error Type Status Code Content Type
errors.SDKError 4XX, 5XX */*