@crowdin/crowdin-api-client
Version:
JavaScript library for Crowdin API
220 lines (219 loc) • 9.66 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Glossaries = void 0;
const core_1 = require("../core");
/**
* Glossaries help to explain some specific terms or the ones often used in the project so that they can be properly and consistently translated.
*
* Use API to manage glossaries or specific terms.
* Glossary export and import are asynchronous operations and shall be completed with sequence of API methods.
*/
class Glossaries extends core_1.CrowdinApi {
listGlossaries(options, deprecatedLimit, deprecatedOffset) {
if ((0, core_1.isOptionalNumber)(options, '0' in arguments)) {
options = { groupId: options, limit: deprecatedLimit, offset: deprecatedOffset };
}
let url = `${this.url}/glossaries`;
url = this.addQueryParam(url, 'groupId', options.groupId);
url = this.addQueryParam(url, 'orderBy', options.orderBy);
url = this.addQueryParam(url, 'userId', options.userId);
return this.getList(url, options.limit, options.offset);
}
/**
* @param request request body
* @see https://developer.crowdin.com/api/v2/#operation/api.glossaries.post
*/
addGlossary(request) {
const url = `${this.url}/glossaries`;
return this.post(url, request, this.defaultConfig());
}
/**
* @param glossaryId glossary identifier
* @see https://developer.crowdin.com/api/v2/#operation/api.glossaries.get
*/
getGlossary(glossaryId) {
const url = `${this.url}/glossaries/${glossaryId}`;
return this.get(url, this.defaultConfig());
}
/**
* @param glossaryId glossary identifier
* @see https://developer.crowdin.com/api/v2/#operation/api.glossaries.delete
*/
deleteGlossary(glossaryId) {
const url = `${this.url}/glossaries/${glossaryId}`;
return this.delete(url, this.defaultConfig());
}
/**
* @param glossaryId glossary identifier
* @param request request body
* @see https://developer.crowdin.com/api/v2/#operation/api.glossaries.patch
*/
editGlossary(glossaryId, request) {
const url = `${this.url}/glossaries/${glossaryId}`;
return this.patch(url, request, this.defaultConfig());
}
/**
* @param glossaryId glossary identifier
* @param request request body
* @see https://developer.crowdin.com/api/v2/#operation/api.glossaries.exports.post
*/
exportGlossary(glossaryId, request) {
const url = `${this.url}/glossaries/${glossaryId}/exports`;
return this.post(url, request, this.defaultConfig());
}
/**
* @param glossaryId glossary identifier
* @param exportId export identifier
* @see https://developer.crowdin.com/api/v2/#operation/api.glossaries.exports.get
*/
checkGlossaryExportStatus(glossaryId, exportId) {
const url = `${this.url}/glossaries/${glossaryId}/exports/${exportId}`;
return this.get(url, this.defaultConfig());
}
/**
* @param glossaryId glossary identifier
* @param exportId export identifier
* @see https://developer.crowdin.com/api/v2/#operation/api.glossaries.exports.download.download
*/
downloadGlossary(glossaryId, exportId) {
const url = `${this.url}/glossaries/${glossaryId}/exports/${exportId}/download`;
return this.get(url, this.defaultConfig());
}
/**
* @param glossaryId glossary identifier
* @param request request body
* @see https://developer.crowdin.com/api/v2/#operation/api.glossaries.imports.post
*/
importGlossaryFile(glossaryId, request) {
const url = `${this.url}/glossaries/${glossaryId}/imports`;
return this.post(url, request, this.defaultConfig());
}
/**
* @param glossaryId glossary identifier
* @param importId import identifier
* @see https://developer.crowdin.com/api/v2/#operation/api.glossaries.imports.get
*/
checkGlossaryImportStatus(glossaryId, importId) {
const url = `${this.url}/glossaries/${glossaryId}/imports/${importId}`;
return this.get(url, this.defaultConfig());
}
listTerms(glossaryId, options, deprecatedLimit, deprecatedOffset, deprecatedLanguageId, deprecatedTranslationOfTermId, deprecatedConceptId) {
let url = `${this.url}/glossaries/${glossaryId}/terms`;
if ((0, core_1.isOptionalNumber)(options, '1' in arguments)) {
options = {
userId: options,
limit: deprecatedLimit,
offset: deprecatedOffset,
languageId: deprecatedLanguageId,
translationOfTermId: deprecatedTranslationOfTermId,
conceptId: deprecatedConceptId,
};
}
url = this.addQueryParam(url, 'userId', options.userId);
url = this.addQueryParam(url, 'languageId', options.languageId);
url = this.addQueryParam(url, 'translationOfTermId', options.translationOfTermId);
url = this.addQueryParam(url, 'conceptId', options.conceptId);
url = this.addQueryParam(url, 'orderBy', options.orderBy);
url = this.addQueryParam(url, 'croql', options.croql);
return this.getList(url, options.limit, options.offset);
}
/**
* @param glossaryId glossary identifier
* @param request request body
* @see https://developer.crowdin.com/api/v2/#operation/api.glossaries.terms.post
*/
addTerm(glossaryId, request) {
const url = `${this.url}/glossaries/${glossaryId}/terms`;
return this.post(url, request, this.defaultConfig());
}
clearGlossary(glossaryId, options, deprecatedTranslationOfTermId, deprecatedConceptId) {
if ((0, core_1.isOptionalNumber)(options, '1' in arguments)) {
options = {
languageId: options,
translationOfTermId: deprecatedTranslationOfTermId,
conceptId: deprecatedConceptId,
};
}
let url = `${this.url}/glossaries/${glossaryId}/terms`;
url = this.addQueryParam(url, 'languageId', options.languageId);
url = this.addQueryParam(url, 'translationOfTermId', options.translationOfTermId);
url = this.addQueryParam(url, 'conceptId', options.conceptId);
return this.delete(url, this.defaultConfig());
}
/**
* @param glossaryId glossary identifier
* @param termId term identifier
* @see https://developer.crowdin.com/api/v2/#operation/api.glossaries.terms.get
*/
getTerm(glossaryId, termId) {
const url = `${this.url}/glossaries/${glossaryId}/terms/${termId}`;
return this.get(url, this.defaultConfig());
}
/**
* @param glossaryId glossary identifier
* @param termId term identifier
* @see https://developer.crowdin.com/api/v2/#operation/api.glossaries.terms.delete
*/
deleteTerm(glossaryId, termId) {
const url = `${this.url}/glossaries/${glossaryId}/terms/${termId}`;
return this.delete(url, this.defaultConfig());
}
/**
* @param glossaryId glossary identifier
* @param termId term identifier
* @param request request body
* @see https://developer.crowdin.com/api/v2/#operation/api.glossaries.terms.patch
*/
editTerm(glossaryId, termId, request) {
const url = `${this.url}/glossaries/${glossaryId}/terms/${termId}`;
return this.patch(url, request, this.defaultConfig());
}
/**
* @param glossaryId glossary identifier
* @param options optional parameters for the request
* @see https://developer.crowdin.com/api/v2/#operation/api.glossaries.concepts.getMany
*/
listConcepts(glossaryId, options) {
let url = `${this.url}/glossaries/${glossaryId}/concepts`;
url = this.addQueryParam(url, 'orderBy', options === null || options === void 0 ? void 0 : options.orderBy);
return this.getList(url, options === null || options === void 0 ? void 0 : options.limit, options === null || options === void 0 ? void 0 : options.offset);
}
/**
* @param glossaryId glossary identifier
* @param conceptId concept identifier
* @see https://developer.crowdin.com/api/v2/#operation/api.glossaries.concepts.get
*/
getConcept(glossaryId, conceptId) {
const url = `${this.url}/glossaries/${glossaryId}/concepts/${conceptId}`;
return this.get(url, this.defaultConfig());
}
/**
* @param glossaryId glossary identifier
* @param conceptId concept identifier
* @param request request body
* @see https://developer.crowdin.com/api/v2/#operation/api.glossaries.concepts.put
*/
updateConcept(glossaryId, conceptId, request) {
const url = `${this.url}/glossaries/${glossaryId}/concepts/${conceptId}`;
return this.put(url, request, this.defaultConfig());
}
/**
* @param glossaryId glossary identifier
* @param conceptId concept identifier
* @see https://developer.crowdin.com/api/v2/#operation/api.glossaries.concepts.delete
*/
deleteConcept(glossaryId, conceptId) {
const url = `${this.url}/glossaries/${glossaryId}/concepts/${conceptId}`;
return this.delete(url, this.defaultConfig());
}
/**
* @param projectId project identifier
* @param request request body
* @see https://developer.crowdin.com/api/v2/#operation/api.projects.glossaries.concordance.post
*/
concordanceSearch(projectId, request) {
const url = `${this.url}/projects/${projectId}/glossaries/concordance`;
return this.post(url, request, this.defaultConfig());
}
}
exports.Glossaries = Glossaries;