Skip to content

Commit b14530f

Browse files
author
devkadirselcuk
authored
Merge pull request #16 from crowdin/master
[pull] master from crowdin:master
2 parents b45164c + dac3c8a commit b14530f

File tree

6 files changed

+1251
-2965
lines changed

6 files changed

+1251
-2965
lines changed

.husky/pre-commit

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
. "$(dirname "$0")/_/husky.sh"
3+
4+
npm run lint-ci && npm test

package-lock.json

Lines changed: 1171 additions & 2954 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@crowdin/crowdin-api-client",
3-
"version": "1.12.0",
3+
"version": "1.12.2",
44
"description": "JavaScript library for Crowdin API v2.",
55
"main": "out/index.js",
66
"types": "out/index.d.ts",
@@ -12,6 +12,7 @@
1212
"out/**/*"
1313
],
1414
"scripts": {
15+
"prepare": "husky install",
1516
"test": "jest --config jestconfig.json",
1617
"build": "tsc -p ./",
1718
"watch": "tsc -watch -p ./",
@@ -25,31 +26,26 @@
2526
"license": "MIT",
2627
"devDependencies": {
2728
"@types/node": "^12.0.10",
28-
"@types/jest": "^26.0.0",
29+
"@types/jest": "^27.0.0",
2930
"@types/nock": "^10.0.3",
3031
"@typescript-eslint/eslint-plugin": "^2.3.1",
3132
"@typescript-eslint/parser": "^2.3.1",
3233
"eslint": "^6.4.0",
3334
"eslint-config-prettier": "^6.3.0",
3435
"eslint-plugin-prettier": "^3.1.1",
35-
"husky": ">=1",
36-
"jest": "^26.4.0",
37-
"jest-circus": "^26.4.0",
36+
"husky": "^7.0.0",
37+
"jest": "^27.0.0",
38+
"jest-circus": "^27.0.0",
3839
"lint-staged": ">=8",
3940
"nock": "^10.0.6",
4041
"prettier": "^1.18.2",
41-
"ts-jest": "^26.4.0",
42+
"ts-jest": "^27.0.0",
4243
"typescript": "^4.1.2",
4344
"jest-junit": "^12.0.0"
4445
},
4546
"dependencies": {
4647
"axios": "0.21.3"
4748
},
48-
"husky": {
49-
"hooks": {
50-
"pre-commit": "lint-staged && npm run test"
51-
}
52-
},
5349
"lint-staged": {
5450
"*.js": [
5551
"eslint --fix",

src/sourceStrings/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export class SourceStrings extends CrowdinApi {
1717
* @param scope specify field to be the target of filtering
1818
* @param croql filter strings by CroQL (Can't be used with `labelIds`, `filter` or `scope` in same request)
1919
* @param branchId filter by branch identifier
20+
* @param directoryId filter by directory identifier
2021
*/
2122
listProjectStrings(
2223
projectId: number,
@@ -29,6 +30,7 @@ export class SourceStrings extends CrowdinApi {
2930
scope?: SourceStringsModel.Scope,
3031
croql?: string,
3132
branchId?: number,
33+
directoryId?: number,
3234
): Promise<ResponseList<SourceStringsModel.String>>;
3335

3436
listProjectStrings(
@@ -42,6 +44,7 @@ export class SourceStrings extends CrowdinApi {
4244
scope?: SourceStringsModel.Scope,
4345
croql?: string,
4446
branchId?: number,
47+
directoryId?: number,
4548
): Promise<ResponseList<SourceStringsModel.String>> {
4649
let url = `${this.url}/projects/${projectId}/strings`;
4750
let request: SourceStringsModel.ListProjectStringsRequest;
@@ -58,6 +61,7 @@ export class SourceStrings extends CrowdinApi {
5861
scope,
5962
croql,
6063
branchId,
64+
directoryId,
6165
};
6266
}
6367
url = this.addQueryParam(url, 'fileId', request.fileId);
@@ -67,6 +71,7 @@ export class SourceStrings extends CrowdinApi {
6771
url = this.addQueryParam(url, 'scope', request.scope);
6872
url = this.addQueryParam(url, 'croql', request.croql);
6973
url = this.addQueryParam(url, 'branchId', request.branchId);
74+
url = this.addQueryParam(url, 'directoryId', request.directoryId);
7075
return this.getList(url, request.limit, request.offset);
7176
}
7277

@@ -126,6 +131,7 @@ export namespace SourceStringsModel {
126131
scope?: SourceStringsModel.Scope;
127132
croql?: string;
128133
branchId?: number;
134+
directoryId?: number;
129135
}
130136

131137
export interface String {

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)