Skip to content

Commit 08d96f0

Browse files
authored
feat: add support for pre-translation report endpoint (crowdin#542)
1 parent 9d3440e commit 08d96f0

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed

src/translations/index.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
ResponseObject,
99
Status,
1010
} from '../core';
11+
import { ProjectsGroupsModel } from '../projectsGroups';
1112

1213
/**
1314
* 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 {
7071
return this.patch(url, request, this.defaultConfig());
7172
}
7273

74+
/**
75+
* @param projectId project identifier
76+
* @param preTranslationId pre translation identifier
77+
* @see https://developer.crowdin.com/api/v2/#operation/api.projects.pre-translations.report.getReport
78+
*/
79+
getPreTranslationReport(
80+
projectId: number,
81+
preTranslationId: string,
82+
): Promise<ResponseObject<TranslationsModel.PreTranslationReport>> {
83+
const url = `${this.url}/projects/${projectId}/pre-translations/${preTranslationId}/report`;
84+
return this.get(url, this.defaultConfig());
85+
}
86+
7387
/**
7488
* @param projectId project identifier
7589
* @param directoryId directory identifier
@@ -419,4 +433,30 @@ export namespace TranslationsModel {
419433
export interface ListProjectBuildsOptions extends PaginationOptions {
420434
branchId?: number;
421435
}
436+
437+
export interface PreTranslationReport {
438+
languages: TargetLanguage[];
439+
preTranslateType: Method;
440+
}
441+
442+
export interface TargetLanguage {
443+
id: string;
444+
files: TargetLanguageFile[];
445+
skipped: SkippedInfo;
446+
skippedQaCheckCategories: ProjectsGroupsModel.CheckCategories;
447+
}
448+
449+
export interface TargetLanguageFile {
450+
id: string;
451+
statistics: TargetLanguageFileStatistics;
452+
}
453+
454+
export interface TargetLanguageFileStatistics {
455+
phrases: number;
456+
words: number;
457+
}
458+
459+
export interface SkippedInfo {
460+
[key: string]: any;
461+
}
422462
}

tests/translations/api.test.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,32 @@ describe('Translations API', () => {
9292
identifier: preTranslationId,
9393
},
9494
})
95+
.get(`/projects/${projectId}/pre-translations/${preTranslationId}/report`, undefined, {
96+
reqheaders: {
97+
Authorization: `Bearer ${api.token}`,
98+
},
99+
})
100+
.reply(200, {
101+
data: {
102+
languages: [
103+
{
104+
id: languageId,
105+
files: [
106+
{
107+
id: fileId.toString(),
108+
statistics: {
109+
phrases: 10,
110+
words: 25,
111+
},
112+
},
113+
],
114+
skipped: {},
115+
skippedQaCheckCategories: {},
116+
},
117+
],
118+
preTranslateType: 'ai',
119+
},
120+
})
95121
.post(
96122
`/projects/${projectId}/translations/builds/directories/${directoryId}`,
97123
{
@@ -305,6 +331,17 @@ describe('Translations API', () => {
305331
expect(preTranslation.data.identifier).toBe(preTranslationId);
306332
});
307333

334+
it('Get Pre-translation Report', async () => {
335+
const report = await api.getPreTranslationReport(projectId, preTranslationId);
336+
expect(report.data.languages.length).toBe(1);
337+
expect(report.data.languages[0].id).toBe(languageId);
338+
expect(report.data.languages[0].files.length).toBe(1);
339+
expect(report.data.languages[0].files[0].id).toBe(fileId.toString());
340+
expect(report.data.languages[0].files[0].statistics.phrases).toBe(10);
341+
expect(report.data.languages[0].files[0].statistics.words).toBe(25);
342+
expect(report.data.preTranslateType).toBe('ai');
343+
});
344+
308345
it('Build Project Direcotry Translation', async () => {
309346
const result = await api.buildProjectDirectoryTranslation(projectId, directoryId, {
310347
targetLanguageIds: [languageId],

0 commit comments

Comments
 (0)