Skip to content

Commit 7f609ac

Browse files
committed
[Components] crowdin #13242
Sources - New Comment Issue (Instant) - File Approved (Instant) - New Directory Actions - Create Project - Upload File - Translate Via Machine Translation
1 parent 1e5d90e commit 7f609ac

File tree

17 files changed

+888
-533
lines changed

17 files changed

+888
-533
lines changed

components/crowdin/.gitignore

Lines changed: 0 additions & 3 deletions
This file was deleted.

components/crowdin/actions/upload-file/upload-file.mjs renamed to components/crowdin/actions/add-file/add-file.mjs

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
import { TYPE_OPTIONS } from "../../common/constants.mjs";
2+
import { parseObject } from "../../common/utils.mjs";
13
import crowdin from "../../crowdin.app.mjs";
2-
import { axios } from "@pipedream/platform";
34

45
export default {
5-
key: "crowdin-upload-file",
6-
name: "Upload File to Project",
7-
description: "Uploads a file into the created project. [See the documentation](https://developer.crowdin.com/api/v2/#tag/source-files/operation/api.projects.files.post)",
8-
version: "0.0.{{ts}}",
6+
key: "crowdin-add-file",
7+
name: "Add File to Project",
8+
description: "Adds a file into the created project. [See the documentation](https://developer.crowdin.com/api/v2/#tag/source-files/operation/api.projects.files.post)",
9+
version: "0.0.1",
910
type: "action",
1011
props: {
1112
crowdin,
@@ -24,7 +25,7 @@ export default {
2425
name: {
2526
type: "string",
2627
label: "Name",
27-
description: "The name of the file in Crowdin",
28+
description: "The name of the file in Crowdin. **Note:** Can't contain `\\ / : * ? \" < > |` symbols. `ZIP` files are not allowed.",
2829
},
2930
branchId: {
3031
propDefinition: [
@@ -47,25 +48,26 @@ export default {
4748
title: {
4849
type: "string",
4950
label: "Title",
50-
description: "The title of the file",
51+
description: "Use to provide more details for translators. Title is available in UI only",
5152
optional: true,
5253
},
5354
context: {
5455
type: "string",
5556
label: "Context",
56-
description: "The context of the file",
57+
description: "Use to provide context about whole file",
5758
optional: true,
5859
},
5960
type: {
6061
type: "string",
6162
label: "File Type",
62-
description: "The type of the file",
63+
description: "The type of the file. **Note:** Use `docx` type to import each cell as a separate source string for XLSX file. Default is `auto`",
64+
options: TYPE_OPTIONS,
6365
optional: true,
6466
},
6567
parserVersion: {
6668
type: "integer",
6769
label: "Parser Version",
68-
description: "The version of the parser",
70+
description: "Using latest parser version by default. **Note:** Must be used together with `type`.",
6971
optional: true,
7072
},
7173
attachLabelIds: {
@@ -79,24 +81,21 @@ export default {
7981
},
8082
},
8183
async run({ $ }) {
82-
const params = {
83-
projectId: this.projectId,
84-
storageId: this.storageId,
85-
name: this.name,
86-
branchId: this.branchId,
87-
directoryId: this.directoryId,
88-
title: this.title,
89-
context: this.context,
90-
type: this.type,
91-
parserVersion: this.parserVersion,
92-
attachLabelIds: this.attachLabelIds,
93-
};
84+
const {
85+
crowdin,
86+
attachLabelIds,
87+
projectId,
88+
...data
89+
} = this;
9490

95-
const data = Object.fromEntries(Object.entries(params).filter(([
96-
, v,
97-
]) => v !== undefined && v !== ""));
98-
99-
const response = await this.crowdin.uploadFileToProject(data);
91+
const response = await crowdin.uploadFileToProject({
92+
$,
93+
projectId,
94+
data: {
95+
...data,
96+
attachLabelIds: parseObject(attachLabelIds),
97+
},
98+
});
10099
$.export("$summary", `Successfully uploaded file: ${this.name}`);
101100
return response;
102101
},
Lines changed: 57 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1+
import { ConfigurationError } from "@pipedream/platform";
2+
import {
3+
LANGUAGE_ACCESS_POLICY_OPTIONS,
4+
TAGS_DETECTION_OPTIONS,
5+
VISIBILITY_OPTIONS,
6+
} from "../../common/constants.mjs";
7+
import { parseObject } from "../../common/utils.mjs";
18
import crowdin from "../../crowdin.app.mjs";
2-
import { axios } from "@pipedream/platform";
39

410
export default {
511
key: "crowdin-create-project",
612
name: "Create Project",
713
description: "Creates a new project within Crowdin. [See the documentation](https://support.crowdin.com/developer/api/v2/#/projects-api/create-project)",
8-
version: "0.0.{{ts}}",
14+
version: "0.0.1",
915
type: "action",
1016
props: {
1117
crowdin,
@@ -23,8 +29,11 @@ export default {
2329
targetLanguageIds: {
2430
propDefinition: [
2531
crowdin,
26-
"targetLanguageIds",
32+
"sourceLanguageId",
2733
],
34+
type: "string[]",
35+
label: "Target Language IDs",
36+
description: "Array of target language IDs",
2837
optional: true,
2938
},
3039
identifier: {
@@ -33,33 +42,19 @@ export default {
3342
description: "A custom identifier for the project",
3443
optional: true,
3544
},
36-
type: {
37-
type: "integer",
38-
label: "Type",
39-
description: "Defines the project type. To create a file-based project, use 0.",
40-
optional: true,
41-
},
4245
visibility: {
4346
type: "string",
4447
label: "Visibility",
4548
description: "Defines how users can join the project.",
49+
options: VISIBILITY_OPTIONS,
4650
optional: true,
47-
options: [
48-
"open",
49-
"private",
50-
],
51-
default: "private",
5251
},
5352
languageAccessPolicy: {
5453
type: "string",
5554
label: "Language Access Policy",
5655
description: "Defines access to project languages.",
5756
optional: true,
58-
options: [
59-
"open",
60-
"moderate",
61-
],
62-
default: "open",
57+
options: LANGUAGE_ACCESS_POLICY_OPTIONS,
6358
},
6459
cname: {
6560
type: "string",
@@ -74,64 +69,61 @@ export default {
7469
optional: true,
7570
},
7671
tagsDetection: {
77-
type: "integer",
72+
type: "string",
7873
label: "Tags Detection",
79-
description: "Values available: 0 - Auto, 1 - Count tags, 2 - Skip tags.",
74+
description: "The type of the tags detection.",
75+
options: TAGS_DETECTION_OPTIONS,
8076
optional: true,
81-
default: 0,
8277
},
8378
isMtAllowed: {
8479
type: "boolean",
8580
label: "Allow Machine Translation",
86-
description: "Allows machine translations to be visible for translators.",
81+
description: "Allows machine translations to be visible for translators. Default is **true**.",
8782
optional: true,
88-
default: true,
8983
},
9084
taskBasedAccessControl: {
9185
type: "boolean",
9286
label: "Task Based Access Control",
93-
description: "Allow project members to work with tasks they're assigned to.",
87+
description: "Allow project members to work with tasks they're assigned to. Default is **false**.",
9488
optional: true,
9589
default: false,
9690
},
9791
autoSubstitution: {
9892
type: "boolean",
9993
label: "Auto Substitution",
100-
description: "Allows auto-substitution.",
94+
description: "Allows auto-substitution. Default is **true**.",
10195
optional: true,
10296
default: true,
10397
},
10498
autoTranslateDialects: {
10599
type: "boolean",
106100
label: "Auto Translate Dialects",
107-
description: "Automatically fill in regional dialects.",
101+
description: "Automatically fill in regional dialects. Default is **false**.",
108102
optional: true,
109-
default: false,
110103
},
111104
publicDownloads: {
112105
type: "boolean",
113106
label: "Public Downloads",
114-
description: "Allows translators to download source files.",
107+
description: "Allows translators to download source files. Default is **true**.",
115108
optional: true,
116-
default: true,
117109
},
118110
hiddenStringsProofreadersAccess: {
119111
type: "boolean",
120112
label: "Hidden Strings Proofreaders Access",
121-
description: "Allows proofreaders to work with hidden strings.",
113+
description: "Allows proofreaders to work with hidden strings. Default is **true**.",
122114
optional: true,
123115
default: true,
124116
},
125117
useGlobalTm: {
126118
type: "boolean",
127119
label: "Use Global Translation Memory",
128-
description: "If true, machine translations from connected MT engines will appear as suggestions.",
120+
description: "If true, machine translations from connected MT engines will appear as suggestions. Default is **true**.",
129121
optional: true,
130122
},
131123
showTmSuggestionsDialects: {
132124
type: "boolean",
133125
label: "Show TM Suggestions for Dialects",
134-
description: "Show primary language TM suggestions for dialects if there are no dialect-specific ones.",
126+
description: "Show primary language TM suggestions for dialects if there are no dialect-specific ones. Default is **true**.",
135127
optional: true,
136128
default: true,
137129
},
@@ -150,80 +142,43 @@ export default {
150142
qaCheckIsActive: {
151143
type: "boolean",
152144
label: "QA Check Is Active",
153-
description: "If true, QA checks are active.",
145+
description: "If true, QA checks are active. Default is **true**.",
154146
optional: true,
155-
default: true,
156147
},
157-
savingsReportSettingsTemplateId: {
158-
type: "integer",
159-
label: "Savings Report Settings Template ID",
160-
description: "Report Settings Templates Identifier.",
161-
optional: true,
162-
async options() {
163-
const templates = await this.crowdin.listSavingsReportSettingsTemplates();
164-
return templates.map((template) => ({
165-
label: template.name,
166-
value: template.id,
167-
}));
168-
},
169-
},
170-
defaultTmId: {
171-
type: "integer",
172-
label: "Default TM ID",
173-
description: "Translation Memory ID. If omitted, a new translation memory will be created.",
174-
optional: true,
175-
async options() {
176-
const tms = await this.crowdin.listTMs();
177-
return tms.map((tm) => ({
178-
label: tm.name,
179-
value: tm.id,
180-
}));
181-
},
182-
},
183-
defaultGlossaryId: {
184-
type: "integer",
185-
label: "Default Glossary ID",
186-
description: "Glossary ID. If omitted, a new Glossary will be created.",
187-
optional: true,
188-
async options() {
189-
const glossaries = await this.crowdin.listGlossaries();
190-
return glossaries.map((glossary) => ({
191-
label: glossary.name,
192-
value: glossary.id,
193-
}));
194-
},
148+
type: {
149+
type: "string",
150+
label: "Type",
151+
description: "Defines the project type. To create a file-based project, use 0.",
152+
options: [
153+
"0",
154+
"1",
155+
],
156+
optional: true,
195157
},
196158
},
197159
async run({ $ }) {
198-
const data = {
199-
name: this.name,
200-
sourceLanguageId: this.sourceLanguageId,
201-
identifier: this.identifier,
202-
type: this.type,
203-
targetLanguageIds: this.targetLanguageIds,
204-
visibility: this.visibility,
205-
languageAccessPolicy: this.languageAccessPolicy,
206-
cname: this.cname,
207-
description: this.description,
208-
tagsDetection: this.tagsDetection,
209-
isMtAllowed: this.isMtAllowed,
210-
taskBasedAccessControl: this.taskBasedAccessControl,
211-
autoSubstitution: this.autoSubstitution,
212-
autoTranslateDialects: this.autoTranslateDialects,
213-
publicDownloads: this.publicDownloads,
214-
hiddenStringsProofreadersAccess: this.hiddenStringsProofreadersAccess,
215-
useGlobalTm: this.useGlobalTm,
216-
showTmSuggestionsDialects: this.showTmSuggestionsDialects,
217-
skipUntranslatedStrings: this.skipUntranslatedStrings,
218-
exportApprovedOnly: this.exportApprovedOnly,
219-
qaCheckIsActive: this.qaCheckIsActive,
220-
savingsReportSettingsTemplateId: this.savingsReportSettingsTemplateId,
221-
defaultTmId: this.defaultTmId,
222-
defaultGlossaryId: this.defaultGlossaryId,
223-
};
160+
try {
161+
const {
162+
crowdin,
163+
type,
164+
targetLanguageIds,
165+
tagsDetection,
166+
...data
167+
} = this;
224168

225-
const response = await this.crowdin.createProject(data);
226-
$.export("$summary", `Project "${response.name}" created successfully`);
227-
return response;
169+
const response = await crowdin.createProject({
170+
$,
171+
data: {
172+
...data,
173+
type: parseInt(type),
174+
targetLanguageIds: parseObject(targetLanguageIds),
175+
tagsDetection: parseInt(tagsDetection),
176+
},
177+
});
178+
$.export("$summary", `Project created successfully with Id: ${response.data.id}`);
179+
return response;
180+
} catch ({ response }) {
181+
throw new ConfigurationError(response.data.errors[0]?.error?.errors[0]?.message);
182+
}
228183
},
229184
};

0 commit comments

Comments
 (0)