@crowdin/crowdin-api-client
Version:
JavaScript library for Crowdin API
144 lines (143 loc) • 6.7 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Translations = void 0;
const core_1 = require("../core");
/**
* Translators can work with entirely untranslated project or you can pre-translate the files to ease the translations process.
*
* Use API to pre-translate files via Machine Translation (MT) or Translation Memory (TM), upload your existing translations, and download translations correspondingly.
* Pre-translate and build are asynchronous operations and shall be completed with sequence of API methods.
*/
class Translations extends core_1.CrowdinApi {
/**
* @param projectId project identifier
* @param options optional parameters for the request
* @see https://developer.crowdin.com/api/v2/#operation/api.projects.pre-translations.getMany
*/
listPreTranslations(projectId, options) {
const url = `${this.url}/projects/${projectId}/pre-translations`;
return this.getList(url, options === null || options === void 0 ? void 0 : options.limit, options === null || options === void 0 ? void 0 : options.offset);
}
/**
* @param projectId project identifier
* @param preTranslationId pre translation identifier
* @see https://developer.crowdin.com/api/v2/#tag/Translations/paths/~1projects~1{projectId}~1pre-translations~1{preTranslationId}/get
*/
preTranslationStatus(projectId, preTranslationId) {
const url = `${this.url}/projects/${projectId}/pre-translations/${preTranslationId}`;
return this.get(url, this.defaultConfig());
}
/**
* @param projectId project identifier
* @param request request body
* @see https://developer.crowdin.com/api/v2/#operation/api.projects.pre-translations.post
*/
applyPreTranslation(projectId, request) {
const url = `${this.url}/projects/${projectId}/pre-translations`;
return this.post(url, request, this.defaultConfig());
}
/**
* @param projectId project identifier
* @param preTranslationId pre translation identifier
* @param request request body
* @see https://developer.crowdin.com/api/v2/#operation/api.projects.pre-translations.patch
*/
editPreTranslation(projectId, preTranslationId, request) {
const url = `${this.url}/projects/${projectId}/pre-translations/${preTranslationId}`;
return this.patch(url, request, this.defaultConfig());
}
/**
* @param projectId project identifier
* @param directoryId directory identifier
* @param request request body
* @see https://developer.crowdin.com/api/v2/#operation/api.projects.translations.builds.directories.post
*/
buildProjectDirectoryTranslation(projectId, directoryId, request = {}) {
const url = `${this.url}/projects/${projectId}/translations/builds/directories/${directoryId}`;
const config = this.defaultConfig();
return this.post(url, request, config);
}
/**
* @param projectId project identifier
* @param fileId file identifier
* @param request request body
* @param eTag 'If-None-Match' header
* @see https://developer.crowdin.com/api/v2/#operation/api.projects.translations.builds.files.post
*/
buildProjectFileTranslation(projectId, fileId, request, eTag) {
const url = `${this.url}/projects/${projectId}/translations/builds/files/${fileId}`;
const config = this.defaultConfig();
if (eTag) {
config.headers['If-None-Match'] = eTag;
}
return this.post(url, request, config);
}
listProjectBuilds(projectId, options, deprecatedLimit, deprecatedOffset) {
if ((0, core_1.isOptionalNumber)(options, '1' in arguments)) {
options = { branchId: options, limit: deprecatedLimit, offset: deprecatedOffset };
}
let url = `${this.url}/projects/${projectId}/translations/builds`;
url = this.addQueryParam(url, 'branchId', options.branchId);
return this.getList(url, options.limit, options.offset);
}
/**
* @param projectId project identifier
* @param request request body
* @see https://developer.crowdin.com/api/v2/#operation/api.projects.translations.builds.post
*/
buildProject(projectId, request = {}) {
const url = `${this.url}/projects/${projectId}/translations/builds`;
return this.post(url, request, this.defaultConfig());
}
/**
* @param projectId project identifier
* @param languageId language identifier
* @param request request body
* @see https://developer.crowdin.com/api/v2/#operation/api.projects.translations.postOnLanguage
*/
uploadTranslation(projectId, languageId, request) {
const url = `${this.url}/projects/${projectId}/translations/${languageId}`;
return this.post(url, request, this.defaultConfig());
}
uploadTranslationStrings(projectId, languageId, request) {
const url = `${this.url}/projects/${projectId}/translations/${languageId}`;
return this.post(url, request, this.defaultConfig());
}
/**
* @param projectId project identifier
* @param buildId build identifier
* @see https://developer.crowdin.com/api/v2/#operation/api.projects.translations.builds.download.download
*/
downloadTranslations(projectId, buildId) {
const url = `${this.url}/projects/${projectId}/translations/builds/${buildId}/download`;
return this.get(url, this.defaultConfig());
}
/**
* @param projectId project identifier
* @param buildId build identifier
* @see https://developer.crowdin.com/api/v2/#operation/api.projects.translations.builds.get
*/
checkBuildStatus(projectId, buildId) {
const url = `${this.url}/projects/${projectId}/translations/builds/${buildId}`;
return this.get(url, this.defaultConfig());
}
/**
* @param projectId project identifier
* @param buildId build identifier
* @see https://developer.crowdin.com/api/v2/#operation/api.projects.translations.builds.delete
*/
cancelBuild(projectId, buildId) {
const url = `${this.url}/projects/${projectId}/translations/builds/${buildId}`;
return this.delete(url, this.defaultConfig());
}
/**
* @param projectId project identifier
* @param request request body
* @see https://developer.crowdin.com/api/v2/#operation/api.projects.translations.exports.post
*/
exportProjectTranslation(projectId, request) {
const url = `${this.url}/projects/${projectId}/translations/exports`;
return this.post(url, request, this.defaultConfig());
}
}
exports.Translations = Translations;