Skip to content

Commit dac3c8a

Browse files
authored
feat: build project directory translations (crowdin#128)
1 parent 589ec97 commit dac3c8a

File tree

4 files changed

+65
-2
lines changed

4 files changed

+65
-2
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@crowdin/crowdin-api-client",
3-
"version": "1.12.1",
3+
"version": "1.12.2",
44
"description": "JavaScript library for Crowdin API v2.",
55
"main": "out/index.js",
66
"types": "out/index.d.ts",

src/translations/index.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,21 @@ export class Translations extends CrowdinApi {
2525
return this.get(url, this.defaultConfig());
2626
}
2727

28+
/**
29+
* @param projectId project identifier
30+
* @param directoryId directory identifier
31+
* @param request request body
32+
*/
33+
buildProjectDirectoryTranslation(
34+
projectId: number,
35+
directoryId: number,
36+
request: TranslationsModel.BuildProjectDirectoryTranslationRequest,
37+
): Promise<ResponseObject<TranslationsModel.BuildProjectDirectoryTranslationResponse>> {
38+
const url = `${this.url}/projects/${projectId}/translations/builds/directories/${directoryId}`;
39+
const config = this.defaultConfig();
40+
return this.post(url, request, config);
41+
}
42+
2843
/**
2944
* @param projectId project identifier
3045
* @param fileId file identifier
@@ -141,6 +156,29 @@ export namespace TranslationsModel {
141156
markAddedTranslationsAsDone?: boolean;
142157
}
143158

159+
export interface BuildProjectDirectoryTranslationRequest {
160+
targetLanguageIds?: string[];
161+
skipUntranslatedStrings?: boolean;
162+
skipUntranslatedFiles?: boolean;
163+
exportApprovedOnly?: boolean;
164+
exportWithMinApprovalsCount?: number;
165+
}
166+
167+
export interface BuildProjectDirectoryTranslationResponse {
168+
id: number;
169+
projectId: number;
170+
status: BuildStatus;
171+
progress: number;
172+
}
173+
174+
export enum BuildStatus {
175+
CREATED = 'created',
176+
IN_PROGRESS = 'inProgress',
177+
CANCELED = 'canceled',
178+
FAILED = 'failed',
179+
FINISHED = 'finished',
180+
}
181+
144182
export interface BuildProjectFileTranslationRequest {
145183
targetLanguageId: string;
146184
exportAsXliff?: boolean;

tests/translations/api.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ describe('Translations API', () => {
1515
const url = 'test.com';
1616
const storageId = 5;
1717
const fileId = 51;
18+
const directoryId = 61;
19+
const progress = 50;
1820
const languageId = 'uk';
1921

2022
const limit = 25;
@@ -48,6 +50,22 @@ describe('Translations API', () => {
4850
identifier: preTranslationId,
4951
},
5052
})
53+
.post(
54+
`/projects/${projectId}/translations/builds/directories/${directoryId}`,
55+
{
56+
targetLanguageIds: [languageId],
57+
},
58+
{
59+
reqheaders: {
60+
Authorization: `Bearer ${api.token}`,
61+
},
62+
},
63+
)
64+
.reply(200, {
65+
data: {
66+
progress,
67+
},
68+
})
5169
.post(
5270
`/projects/${projectId}/translations/builds/files/${fileId}`,
5371
{
@@ -177,6 +195,13 @@ describe('Translations API', () => {
177195
expect(preTranslation.data.identifier).toBe(preTranslationId);
178196
});
179197

198+
it('Build Project Direcotry Translation', async () => {
199+
const result = await api.buildProjectDirectoryTranslation(projectId, directoryId, {
200+
targetLanguageIds: [languageId],
201+
});
202+
expect(result.data.progress).toBe(progress);
203+
});
204+
180205
it('Build Project File Translation', async () => {
181206
const preTranslation = await api.buildProjectFileTranslation(projectId, fileId, {
182207
targetLanguageId: languageId,

0 commit comments

Comments
 (0)