diff --git a/src/translations/index.ts b/src/translations/index.ts index 11d65aca4..86e4d4802 100644 --- a/src/translations/index.ts +++ b/src/translations/index.ts @@ -8,6 +8,7 @@ import { ResponseObject, Status, } from '../core'; +import { ProjectsGroupsModel } from '../projectsGroups'; /** * Translators can work with entirely untranslated project or you can pre-translate the files to ease the translations process. @@ -70,6 +71,19 @@ export class Translations extends CrowdinApi { return this.patch(url, request, this.defaultConfig()); } + /** + * @param projectId project identifier + * @param preTranslationId pre translation identifier + * @see https://developer.crowdin.com/api/v2/#operation/api.projects.pre-translations.report.getReport + */ + getPreTranslationReport( + projectId: number, + preTranslationId: string, + ): Promise> { + const url = `${this.url}/projects/${projectId}/pre-translations/${preTranslationId}/report`; + return this.get(url, this.defaultConfig()); + } + /** * @param projectId project identifier * @param directoryId directory identifier @@ -419,4 +433,30 @@ export namespace TranslationsModel { export interface ListProjectBuildsOptions extends PaginationOptions { branchId?: number; } + + export interface PreTranslationReport { + languages: TargetLanguage[]; + preTranslateType: Method; + } + + export interface TargetLanguage { + id: string; + files: TargetLanguageFile[]; + skipped: SkippedInfo; + skippedQaCheckCategories: ProjectsGroupsModel.CheckCategories; + } + + export interface TargetLanguageFile { + id: string; + statistics: TargetLanguageFileStatistics; + } + + export interface TargetLanguageFileStatistics { + phrases: number; + words: number; + } + + export interface SkippedInfo { + [key: string]: any; + } } diff --git a/tests/translations/api.test.ts b/tests/translations/api.test.ts index e0ad37628..1aca530e5 100644 --- a/tests/translations/api.test.ts +++ b/tests/translations/api.test.ts @@ -92,6 +92,32 @@ describe('Translations API', () => { identifier: preTranslationId, }, }) + .get(`/projects/${projectId}/pre-translations/${preTranslationId}/report`, undefined, { + reqheaders: { + Authorization: `Bearer ${api.token}`, + }, + }) + .reply(200, { + data: { + languages: [ + { + id: languageId, + files: [ + { + id: fileId.toString(), + statistics: { + phrases: 10, + words: 25, + }, + }, + ], + skipped: {}, + skippedQaCheckCategories: {}, + }, + ], + preTranslateType: 'ai', + }, + }) .post( `/projects/${projectId}/translations/builds/directories/${directoryId}`, { @@ -305,6 +331,17 @@ describe('Translations API', () => { expect(preTranslation.data.identifier).toBe(preTranslationId); }); + it('Get Pre-translation Report', async () => { + const report = await api.getPreTranslationReport(projectId, preTranslationId); + expect(report.data.languages.length).toBe(1); + expect(report.data.languages[0].id).toBe(languageId); + expect(report.data.languages[0].files.length).toBe(1); + expect(report.data.languages[0].files[0].id).toBe(fileId.toString()); + expect(report.data.languages[0].files[0].statistics.phrases).toBe(10); + expect(report.data.languages[0].files[0].statistics.words).toBe(25); + expect(report.data.preTranslateType).toBe('ai'); + }); + it('Build Project Direcotry Translation', async () => { const result = await api.buildProjectDirectoryTranslation(projectId, directoryId, { targetLanguageIds: [languageId],