Custom Code is a workflow step that allows you to specify your own code snippets according to which the strings should be filtered further in the workflow. The Custom Code has one input and two outputs (true
and false
), so you can split strings into two workflow threads according to some specific conditions written using JavaScript.
You can use the custom code workflow step in the numerous scenarios. Here are a few examples:
Custom Code could be added to the workflow of your project in the workflow editor or the Workflow template editor.
After you added the Custom Code step to your workflow, it’s necessary to specify the code snippet in the Custom Code field according to which the strings will be directed to either of two outputs.
Code Snippet is JavaScript-based. It Includes a crowdin
object and several properties. To create the code snippet, use this object template for code input:
object crowdin {
object file {
string name,
string fullName,
string title,
string branchName,
string type
}
object context {
string context
?int maxLength
},
string contentType,
string source,
array labels
}
Find the example of a custom code snippet in Crowdin Script Editor. Use the link to see the structure of code snippet, edit it with your data and verify your code is correct.
The code snippet request includes the keys listed below:
contentType – string can include one of three types:
See the example of a code snippet request:
{
"file": {
"name": "strings.json",
"fullName": "backend/strings.json",
"title": "application strings",
"branchName": "master",
"type": "json"
},
"context": {
"context": "backend.string.example.plain",
"maxLength": 10,
"identifier": "6a1821e6499ebae94de4b880fd93b985"
},
"contentType": 'application/vnd.crowdin.text+plural',
"source": '{"one":"Password", "other":"Passwords"}',
"label" : ["Translate by vendor"]
}
After running the code snippet, it should return the response whether the specified conditions are met or not:
success
property indicating whether the specified conditions are met. For instance:{
"success": true
}
false
output of the Custom Code step. For example:{
"success": false
}