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.
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).
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 ProjectsGroupsconst projectsGroupsApi = newProjectsGroups({
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 = newProjectsGroups(credentials, {
retryConfig: {
retries: 2, // amount of retries (gte 0)waitInterval: 100, // wait interval in ms between retriesconditions: [ // 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 });
asyncfunctiontest() {
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');
} elseif (e instanceof crowdin.CrowdinError) {
console.log('Generic error');
}
console.error(e);
}
}
test();
Http request timeout
By default request timeout will vary on http client implementation and/or environment (e.g. fetch uses timeout configured by the browser).
But there is an option to set constant value:
:dizzy: 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.
GraphQL API
This library also provides possibility to use GraphQL API (only for Crowdin Enterprise).
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.
The npm package @crowdin/crowdin-api-client receives a total of 33,558 weekly downloads. As such, @crowdin/crowdin-api-client popularity was classified as popular.
We found that @crowdin/crowdin-api-client demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.It has 3 open source maintainers collaborating on the project.
Package last updated on 02 Jan 2024
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."