UNPKG

@crowdin/crowdin-api-client

Version:
235 lines (234 loc) 11 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.StringTranslations = void 0; const core_1 = require("../core"); /** * Use API to add or remove strings translations, approvals, and votes. */ class StringTranslations extends core_1.CrowdinApi { listTranslationApprovals(projectId, options, deprecatedLanguageId, deprecatedTranslationId, deprecatedLimit, deprecatedOffset, deprecatedFileId, deprecatedLabelIds, deprecatedExcludeLabelIds) { let url = `${this.url}/projects/${projectId}/approvals`; if ((0, core_1.isOptionalNumber)(options, '1' in arguments)) { options = { stringId: options, languageId: deprecatedLanguageId, translationId: deprecatedTranslationId, limit: deprecatedLimit, offset: deprecatedOffset, fileId: deprecatedFileId, labelIds: deprecatedLabelIds, excludeLabelIds: deprecatedExcludeLabelIds, }; } url = this.addQueryParam(url, 'stringId', options.stringId); url = this.addQueryParam(url, 'languageId', options.languageId); url = this.addQueryParam(url, 'translationId', options.translationId); url = this.addQueryParam(url, 'fileId', options.fileId); url = this.addQueryParam(url, 'labelIds', options.labelIds); url = this.addQueryParam(url, 'excludeLabelIds', options.excludeLabelIds); url = this.addQueryParam(url, 'orderBy', options.orderBy); 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.approvals.post */ addApproval(projectId, request) { const url = `${this.url}/projects/${projectId}/approvals`; return this.post(url, request, this.defaultConfig()); } /** * @param projectId project identifier * @param stringId string identifier * @see https://support.crowdin.com/developer/api/v2/#tag/String-Translations/operation/api.projects.approvals.deleteMany */ removeStringApprovals(projectId, stringId) { let url = `${this.url}/projects/${projectId}/approvals`; url = this.addQueryParam(url, 'stringId', stringId); return this.delete(url, this.defaultConfig()); } /** * @param projectId project identifier * @param approvalId approval identifier * @see https://developer.crowdin.com/api/v2/#operation/api.projects.approvals.get */ approvalInfo(projectId, approvalId) { const url = `${this.url}/projects/${projectId}/approvals/${approvalId}`; return this.get(url, this.defaultConfig()); } /** * @param projectId project identifier * @param request request body * @see https://developer.crowdin.com/api/v2/#operation/api.projects.approvals.patch */ approvalBatchOperations(projectId, request) { const url = `${this.url}/projects/${projectId}/approvals`; return this.patch(url, request, this.defaultConfig()); } /** * @param projectId project identifier * @param approvalId approval identifier * @see https://developer.crowdin.com/api/v2/#operation/api.projects.approvals.delete */ removeApproval(projectId, approvalId) { const url = `${this.url}/projects/${projectId}/approvals/${approvalId}`; return this.delete(url, this.defaultConfig()); } listLanguageTranslations(projectId, languageId, options, fileId, limit, offset, labelIds, denormalizePlaceholders, croql) { let url = `${this.url}/projects/${projectId}/languages/${languageId}/translations`; if ((0, core_1.isOptionalString)(options, '2' in arguments)) { options = { stringIds: options, fileId, limit, offset, labelIds, denormalizePlaceholders, croql, }; } url = this.addQueryParam(url, 'stringIds', options.stringIds); url = this.addQueryParam(url, 'fileId', options.fileId); url = this.addQueryParam(url, 'labelIds', options.labelIds); url = this.addQueryParam(url, 'denormalizePlaceholders', options.denormalizePlaceholders); url = this.addQueryParam(url, 'croql', options.croql); url = this.addQueryParam(url, 'orderBy', options.orderBy); url = this.addQueryParam(url, 'approvedOnly', options.approvedOnly); url = this.addQueryParam(url, 'passedWorkflow', options.passedWorkflow); url = this.addQueryParam(url, 'branchId', options.branchId); url = this.addQueryParam(url, 'directoryId', options.directoryId); url = this.addQueryParam(url, 'minApprovalCount', options.minApprovalCount); 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.alignment.post */ translationAlignment(projectId, request) { const url = `${this.url}/projects/${projectId}/translations/alignment`; return this.post(url, request, this.defaultConfig()); } listStringTranslations(projectId, stringId, languageId, options, deprecatedOffset, deprecatedDenormalizePlaceholders) { if ((0, core_1.isOptionalNumber)(options, '3' in arguments)) { options = { limit: options, offset: deprecatedOffset, denormalizePlaceholders: deprecatedDenormalizePlaceholders, }; } let url = `${this.url}/projects/${projectId}/translations`; url = this.addQueryParam(url, 'stringId', stringId); url = this.addQueryParam(url, 'languageId', languageId); url = this.addQueryParam(url, 'denormalizePlaceholders', options.denormalizePlaceholders); url = this.addQueryParam(url, 'orderBy', options.orderBy); 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.post */ addTranslation(projectId, request) { const url = `${this.url}/projects/${projectId}/translations`; return this.post(url, request, this.defaultConfig()); } /** * @param projectId project identifier * @param stringId string identifier * @param languageId language identifier * @see https://developer.crowdin.com/api/v2/#operation/api.projects.translations.deleteMany */ deleteAllTranslations(projectId, stringId, languageId) { let url = `${this.url}/projects/${projectId}/translations`; url = this.addQueryParam(url, 'stringId', stringId); url = this.addQueryParam(url, 'languageId', languageId); return this.delete(url, this.defaultConfig()); } /** * @param projectId project identifier * @param translationId translation identifier * @see https://developer.crowdin.com/api/v2/#operation/api.projects.translations.get */ translationInfo(projectId, translationId) { const url = `${this.url}/projects/${projectId}/translations/${translationId}`; return this.get(url, this.defaultConfig()); } /** * @param projectId project identifier * @param translationId translation identifier * @see https://developer.crowdin.com/api/v2/#operation/api.projects.translations.put */ restoreTranslation(projectId, translationId) { const url = `${this.url}/projects/${projectId}/translations/${translationId}`; return this.put(url, {}, this.defaultConfig()); } /** * @param projectId project identifier * @param request request body * @see https://developer.crowdin.com/api/v2/#operation/api.projects.translations.patch */ translationBatchOperations(projectId, request) { const url = `${this.url}/projects/${projectId}/translations`; return this.patch(url, request, this.defaultConfig()); } /** * @param projectId project identifier * @param translationId translation identifier * @see https://developer.crowdin.com/api/v2/#operation/api.projects.translations.delete */ deleteTranslation(projectId, translationId) { const url = `${this.url}/projects/${projectId}/translations/${translationId}`; return this.delete(url, this.defaultConfig()); } listTranslationVotes(projectId, options, deprecatedLanguageId, deprecatedTranslationId, deprecatedLabelIds, deprecatedExcludeLabelIds, deprecatedLimit, deprecatedOffset) { let url = `${this.url}/projects/${projectId}/votes`; if ((0, core_1.isOptionalNumber)(options, '1' in arguments)) { options = { stringId: options, languageId: deprecatedLanguageId, translationId: deprecatedTranslationId, labelIds: deprecatedLabelIds, excludeLabelIds: deprecatedExcludeLabelIds, limit: deprecatedLimit, offset: deprecatedOffset, }; } url = this.addQueryParam(url, 'stringId', options.stringId); url = this.addQueryParam(url, 'languageId', options.languageId); url = this.addQueryParam(url, 'translationId', options.translationId); url = this.addQueryParam(url, 'labelIds', options.labelIds); url = this.addQueryParam(url, 'excludeLabelIds', options.excludeLabelIds); url = this.addQueryParam(url, 'fileId', options.fileId); 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.votes.post */ addVote(projectId, request) { const url = `${this.url}/projects/${projectId}/votes`; return this.post(url, request, this.defaultConfig()); } /** * @param projectId project identifier * @param voteId vote identifier * @see https://developer.crowdin.com/api/v2/#operation/api.projects.votes.get */ voteInfo(projectId, voteId) { const url = `${this.url}/projects/${projectId}/votes/${voteId}`; return this.get(url, this.defaultConfig()); } /** * @param projectId project identifier * @param voteId vote identifier * @see https://developer.crowdin.com/api/v2/#operation/api.projects.votes.delete */ cancelVote(projectId, voteId) { const url = `${this.url}/projects/${projectId}/votes/${voteId}`; return this.delete(url, this.defaultConfig()); } } exports.StringTranslations = StringTranslations;