自定义代码是一个工作流步骤,允许您指定自己的代码片段,应根据这些代码片段在工作流中进一步过滤字符串。 自定义代码有一个输入和两个输出(true
和 false
),因此您可以根据使用 JavaScript 编写的某些特定条件将字符串拆分为两个工作流线程。
您可以在多种场景中使用自定义代码工作流步骤。 以下是几个例子:
可以在工作流编辑器或工作流模板编辑器中将自定义代码添加到项目的工作流中。
将自定义代码步骤添加到工作流后,需要在自定义代码字段中指定代码片段,字符串将根据该代码片段定向到两个输出之一。
代码片段基于 JavaScript。 它包括一个 crowdin
对象和几个属性。 要创建代码片段,请使用此对象模板输入代码:
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
}
在 Crowdin 脚本编辑器 中查找自定义代码片段的示例。 使用链接查看代码片段的结构,使用您的数据对其进行编辑并验证您的代码是否正确。
代码片段请求包含下面列出的键值:
contentType – 字符串可以包含以下三种类型之一:
参见代码片段请求的示例:
{
"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"]
}
运行代码片段后,无论是否满足指定条件,它都应该返回响应:
success
属性,指示是否满足指定条件。 就像这样:{
"success": true
}
false
输出。 例如:{
"success": false
}