All Projects → crowdin → crowdin-api-client-js

crowdin / crowdin-api-client-js

Licence: MIT license
JavaScript client library for Crowdin API

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to crowdin-api-client-js

HacktoberFest2021
Make your first PR! ~ A beginner-friendly repository made specifically for open source beginners. Add your profile, a blog, or any program under any language or update the existing one. Just make sure to add the file under the correct directory. Happy hacking!
Stars: ✭ 9 (-89.89%)
Mutual labels:  hacktoberfest2022
recent-activity
Add your recent activity to your profile readme!
Stars: ✭ 87 (-2.25%)
Mutual labels:  node-js
node-ctrip-tickets
🚄🚄🚄 Node.js 携程火车票查询,查询有票的列车
Stars: ✭ 12 (-86.52%)
Mutual labels:  node-js
backend-server
📠 The backend of the Fairfield Programming Association website.
Stars: ✭ 26 (-70.79%)
Mutual labels:  node-js
triumph-gui
Simple lib to create inventory GUIs for Bukkit platforms.
Stars: ✭ 196 (+120.22%)
Mutual labels:  hacktoberfest2022
BashBar
No description or website provided.
Stars: ✭ 28 (-68.54%)
Mutual labels:  hacktoberfest2022
WebXDAO.github.io
Main website built with Next.js and Tailwind, and Community builded. 🛸
Stars: ✭ 39 (-56.18%)
Mutual labels:  hacktoberfest2022
titan-starter-website
A Laravel Website and Admin starter project that helps you with the setup.
Stars: ✭ 51 (-42.7%)
Mutual labels:  hacktoberfest2022
biguint-format
Node.js module to format big uint numbers from a byte array or a Buffer
Stars: ✭ 16 (-82.02%)
Mutual labels:  node-js
Online-Chess
A chess website where people can play against each other online.
Stars: ✭ 28 (-68.54%)
Mutual labels:  node-js
trifolia-on-fhir
Sister product to Trifolia Workbench that has native support for FHIR resources
Stars: ✭ 23 (-74.16%)
Mutual labels:  node-js
TinyPNGNodeJSBatcher
提供一个NodeJS环境下,基于TinyPNG服务的,批量压缩任意数量图片的工具。
Stars: ✭ 51 (-42.7%)
Mutual labels:  node-js
midtrans-nodejs-client
Official Midtrans Payment API Client for Node JS | https://midtrans.com
Stars: ✭ 124 (+39.33%)
Mutual labels:  node-js
content-moderation-image-api
An NSFW Image Classification REST API for effortless Content Moderation built with Node.js, Tensorflow, and Parse Server
Stars: ✭ 50 (-43.82%)
Mutual labels:  node-js
teresa
Teresa is a special bot of discord for you.
Stars: ✭ 21 (-76.4%)
Mutual labels:  node-js
winston-dev-console
Winston@3 console format aimed to improve development UX
Stars: ✭ 88 (-1.12%)
Mutual labels:  node-js
SlugTerra
Hactoberfest 2020-2022 Project
Stars: ✭ 35 (-60.67%)
Mutual labels:  hacktoberfest2022
TeachMePythonLikeIm5
Teach the Python programming language using a collection of super beginner friendly tutorials and challenges.
Stars: ✭ 23 (-74.16%)
Mutual labels:  hacktoberfest2022
Registration-and-Login-using-MERN-stack
Simple Registration and Login component with MERN stack
Stars: ✭ 210 (+135.96%)
Mutual labels:  node-js
Tweet-Analysis-With-Kafka-and-Spark
A real time analytics dashboard to analyze the trending hashtags and @ mentions at any location using kafka and spark streaming.
Stars: ✭ 18 (-79.78%)
Mutual labels:  node-js

Crowdin JavaScript client Tweet GitHub Repo stars

The Crowdin JavaScript client is a lightweight interface to the Crowdin API that works in any JavaScript environment, including web browsers, workers in web browsers, extensions in web browsers or desktop applications, Node.js etc. It provides common services for making API requests.

Our API is a full-featured RESTful API that helps you to integrate localization into your development process. The endpoints that we use allow you to easily make calls to retrieve information and to execute actions needed.

Build Status

Linux Windows MacOS
Build Status Build Status Build Status
Azure DevOps tests (branch) Azure DevOps tests (branch) Azure DevOps tests (branch)

Table of Contents

Installation

npm

npm i @crowdin/crowdin-api-client

yarn

yarn add @crowdin/crowdin-api-client

Quick Start

Typescript
import crowdin, { Credentials, SourceFilesModel } from '@crowdin/crowdin-api-client';

// credentials
const credentials: Credentials = {
  token: 'personalAccessToken',
  organization: 'organizationName' // optional
};

// initialization of crowdin client
const {
  projectsGroupsApi,
  uploadStorageApi,
  sourceFilesApi,
  translationsApi
} = new crowdin(credentials);

// get project list
projectsGroupsApi.listProjects()
  .then(projects => console.log(projects))
  .catch(error => console.error(error));

// You can also use async/wait. Add `async` keyword to your outer function/method
async function getProjects() {
  try {
    const projects = await projectsGroupsApi.listProjects();
    console.log(projects);
  } catch (error) {
    console.error(error);
  }
}

// Create file with json content to translate
async function createFile() {
  const projectId = 123;
  const fileData = {
    title: 'Example',
    description: 'Some Text'
  };
  const storage = await uploadStorageApi.addStorage('file1.json', fileDate);
  const file = await sourceFilesApi.createFile(projectId, {
    name: 'file1.json',
    title: 'Sample file',
    storageId: storage.data.id,
    type: 'json'
  });
  console.log(file);
}

// Download translations
async function downloadTranslations() {
  const projectId = 123;
  const fileId = 456;
  const language = 'de';
  const downloadLink = await translationsApi.buildProjectFileTranslation(
    projectId,
    fileId,
    {
      targetLanguageId: language
    }
  );
  const response = await fetch(downloadLink.data.url);
  const translations = await response.json();
  console.log(translations);
}

Or specific API instances:

import { Credentials, ProjectsGroups } from '@crowdin/crowdin-api-client';

// credentials
const credentials: Credentials = {
  token: 'personalAccessToken',
  organization: 'organizationName' // optional
};

// initialization of ProjectsGroups
const projectsGroupsApi = new ProjectsGroups(credentials);

// get project list
projectsGroupsApi.listProjects()
  .then(projects => console.log(projects))
  .catch(error => console.error(error));
Javascript ES6 modules
import crowdin, { SourceFilesModel } from '@crowdin/crowdin-api-client';

// initialization of crowdin client
const {
  projectsGroupsApi,
  uploadStorageApi,
  sourceFilesApi,
  translationsApi
} = new crowdin({
  token: 'personalAccessToken',
  organization: 'organizationName' // optional
});

// get project list
projectsGroupsApi.listProjects()
  .then(projects => console.log(projects))
  .catch(error => console.error(error));

// You can also use async/wait. Add `async` keyword to your outer function/method
async function getProjects() {
  try {
    const projects = await projectsGroupsApi.listProjects();
    console.log(projects);
  } catch (error) {
    console.error(error);
  }
}

// Create file with json content to translate
async function createFile() {
  const projectId = 123;
  const fileData = {
    title: 'Example',
    description: 'Some Text'
  };
  const storage = await uploadStorageApi.addStorage('file1.json', fileDate);
  const file = await sourceFilesApi.createFile(projectId, {
    name: 'file1.json',
    title: 'Sample file',
    storageId: storage.data.id,
    type: 'json'
  });
  console.log(file);
}

// Download translations
async function downloadTranslations() {
  const projectId = 123;
  const fileId = 456;
  const language = 'de';
  const downloadLink = await translationsApi.buildProjectFileTranslation(
    projectId,
    fileId,
    {
      targetLanguageId: language
    }
  );
  const response = await fetch(downloadLink.data.url);
  const translations = await response.json();
  console.log(translations);
}

Or specific API instances:

import { ProjectsGroups } from '@crowdin/crowdin-api-client';

// initialization of ProjectsGroups
const projectsGroupsApi = new ProjectsGroups({
  token: 'personalAccessToken',
  organization: 'organizationName' // optional
});

// get project list
projectsGroupsApi.listProjects()
  .then(projects => console.log(projects))
  .catch(error => console.error(error));
Javascript CommonJS
const crowdin = require('@crowdin/crowdin-api-client');

// initialization of crowdin client
const {
  projectsGroupsApi,
  uploadStorageApi,
  sourceFilesApi,
  translationsApi
} = new crowdin.default({
  token: 'personalAccessToken',
  organization: 'organizationName' // optional
});

// get project list
projectsGroupsApi.listProjects()
  .then(projects => console.log(projects))
  .catch(error => console.error(error));

// You can also use async/wait. Add `async` keyword to your outer function/method
async function getProjects() {
  try {
    const projects = await projectsGroupsApi.listProjects();
    console.log(projects);
  } catch (error) {
    console.error(error);
  }
}

// Create file with json content to translate
async function createFile() {
  const projectId = 123;
  const fileData = {
    title: 'Example',
    description: 'Some Text'
  };
  const storage = await uploadStorageApi.addStorage('file1.json', fileDate);
  const file = await sourceFilesApi.createFile(projectId, {
    name: 'file1.json',
    title: 'Sample file',
    storageId: storage.data.id,
    type: 'json'
  });
  console.log(file);
}

// Download translations
async function downloadTranslations() {
  const projectId = 123;
  const fileId = 456;
  const language = 'de';
  const downloadLink = await translationsApi.buildProjectFileTranslation(
    projectId,
    fileId,
    {
      targetLanguageId: language
    }
  );
  const response = await fetch(downloadLink.data.url);
  const translations = await response.json();
  console.log(translations);
}

Or specific API instances:

const ProjectsGroups = require('@crowdin/crowdin-api-client').ProjectsGroups;

// initialization of ProjectsGroups
const projectsGroupsApi = new ProjectsGroups({
  token: 'personalAccessToken',
  organization: 'organizationName' // optional
});

// get project list
projectsGroupsApi.listProjects()
  .then(projects => console.log(projects))
  .catch(error => console.error(error));

You can generate Personal Access Token in your Crowdin Account Settings.

List of projects with Fetch API

In addition if you use client in non-Node.js environment you might have a troubles with http calls. This client uses axios which internally uses http and https Node modules. So there is an option to use http client based on Fetch API (keep in mind that fetch should be available in global scope).

import { ProjectsGroups } from '@crowdin/crowdin-api-client';

const projectsGroupsApi = new ProjectsGroups(credentials, {
  httpClientType: 'fetch'
});

Or even pass your own http client as httpClient property which should implement HttpClient interface.

Fetch all records

It is possible to fetch all records from paginatable methods (where we have limit and offset in arguments).

import { ProjectsGroups } from '@crowdin/crowdin-api-client';

// initialization of ProjectsGroups
const projectsGroupsApi = new ProjectsGroups({
  token: 'personalAccessToken',
  organization: 'organizationName' // optional
});

// get all projects
projectsGroupsApi
  .withFetchAll()
  .listProjects()
  .then(projects => console.log(projects))
  .catch(error => console.error(error));

// get projects but not more than 1000
projectsGroupsApi
  .withFetchAll(1000)
  .listProjects()
  .then(projects => console.log(projects))
  .catch(error => console.error(error));

Retry configuration

There is a possibility to configure client invoke http calls with retry mechanism.

import { ProjectsGroups } from '@crowdin/crowdin-api-client';

const projectsGroupsApi = new ProjectsGroups(credentials, {
  retryConfig: {
    retries: 2, // amount of retries (gte 0)
    waitInterval: 100, // wait interval in ms between retries
    conditions: [ // array of conditions which will check if retry should not be applied
      {
        test(error) {
          return error.code === 40
        }
      }
    ]
  }
});

Exception handling

In case of error library will throw an Error based exception. This can either be a generic error with an error message and a code, or a validation error that additionally contains validation error codes.

const crowdin = require('@crowdin/crowdin-api-client');

const token = '';

const { translationsApi } = new crowdin.default({ token });

async function test() {
  const project = 123;
  const dir = 456;
  try {
    const res = await translationsApi.buildProjectDirectoryTranslation(project, dir);
    console.log(JSON.stringify(res));
  } catch (e) {
    if (e instanceof crowdin.CrowdinValidationError) {
      console.log('Validation error');
    } else if (e instanceof crowdin.CrowdinError) {
      console.log('Generic error');
    }
    console.error(e);
  }
}

test();

Over-The-Air Content Delivery

💫 Recommended for translations delivery to your website or mobile application.

You can also use the Crowdin OTA Client JS library to send the translated content to your web apps via content delivery. Crowdin Content Delivery uses a CDN vault that mirrors your project’s translated content. The updated translations will become available to users much faster.

Seeking Assistance

If you find any problems or would like to suggest a feature, please read the How can I contribute section in our contributing guidelines.

Need help working with Crowdin JavaScript client or have any questions? Contact Customer Success Service.

Contributing

If you want to contribute please read the Contributing guidelines.

License

The Crowdin JavaScript client is licensed under the MIT License.
See the LICENSE.md file distributed with this work for additional
information regarding copyright ownership.

Except as contained in the LICENSE file, the name(s) of the above copyright
holders shall not be used in advertising or otherwise to promote the sale,
use or other dealings in this Software without prior written authorization.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].