代码片段自定义质量保证检查

自定义品质保证 (QA) 检查可帮助客户和翻译员更正拼写、标点符号、术语、格式等方面的错误。 代码片段是一段可帮助创建自定义品质保证检查并将其集成到 Crowdin 的代码。

代码片段参数

代码片段基于 Javascript。 它包含一个 crowdin 对象和一些属性。 要创建代码片段,请使用此对象模板输入代码:

object crowdin {
 object file {
   string name,
   string fullName,
   string branch,
   string type
 }
 string sourceLanguage,
 string targetLanguage,
 object context {
   string context,
   ?int maxLength,
   ?string pluralForm,
   ?string identifier
 },
 string contentType,
 string source,
 string translation
}

Crowdin 脚本编辑器 中找到自定义品质保证检查代码片段的示例。 使用链接查看代码片段的结构,使用您的数据对其进行编辑并验证您的代码是否正确。

代码片段请求

代码片段请求包含下面列出的键值:

  1. file.name – 源文件名
  2. file.fullName – 项目中源文件的完整路径(如果有则不包括分支)
  3. file.branch – 源文件所在的分支名
  4. file.type – 源文件类型
  5. sourceLanguage – 项目源语言的 Crowdin 代码
  6. targetLanguage – 项目目标语言的 Crowdin 代码
  7. source – 源文本
  8. translation – 翻译后的字符串
  9. context.context – 源字符串上下文
  10. context.maxLength – 翻译字符串的最大长度
  11. context.pluralForm – pluralForm 指示正在翻译的复数形式
  12. context.identifier – 源字符串标识符(键)
  13. contentType – 字符串可以包括 3 种类型之一:

    • text/plain
    • application/vnd.crowdin.text+plural
    • application/vnd.crowdin.text+icu

参见代码片段请求示例:

{
   "file": {
     "name": "strings.json",
     "fullName": "backend/strings.json",
     "branch": "master",
     "type": "json"
   }
   "sourceLanguage": 'en',
   "targetLanguage": 'de',
   "context": {
     "context": "backend.string.example.plain",
     "maxLength": 10,
     "pluralForm": 'one',
     "identifier": "6a1821e6499ebae94de4b880fd93b985"       
   },
   "contentType": 'application/vnd.crowdin.text+plural',
   "source": '{"one":"Password", "other":"Passwords"}',
   "translation": 'das Passwort '
}

代码片段响应

运行代码片段后,它应该返回自定义品质保证检查是否成功通过的响应:

  • 响应对象应包含布尔值 success 属性,指示品质保证检查是否已通过。 就像这样:
{
  "success": true
}
  • 如果品质保证检查失败,属性“message”将显示给翻译员。 例如:
{
  "success": false,
  "message": "The sentence starts with space, please remove 1 space at the beginning of the translation.",
  "fixes": [
     {
          "from_pos": 0,
          "to_pos": 1,
          "replacement": ""
     }
  ]
} 
  • Crowdin 品质保证检查还可以将错误和自动修复指令返回给编辑器。 如果可以,建议包含 fixes 属性(对象数组),因为它可以为译者节省大量时间和精力。
{
     "from_pos": 0,
     "to_pos": 1,
     "replacement": ""
}

from_postranslation 字符串中开始替换的字符位置。 to_pos 是字符的结束位置。 replacement 属性是应该放在 from_posto_pos 之间的文本。

另请参阅

本文是否有帮助?