跳转到内容

翻译对齐处理模块

翻译对齐处理模块允许您在上传非键值文件(例如 HTML、MD)的翻译时,覆盖 Crowdin 的默认对齐机制。

默认情况下,Crowdin 会自动将上传的翻译与现有源字符串对齐。 当您在 Crowdin 应用中使用此模块时,可以拦截此过程并应用您自己的自定义对齐逻辑,例如使用第三方对齐服务。 这使您能够完全控制翻译如何映射到复杂文档格式中对应的源字符串。

您可以将此模块的访问权限授予以下用户类别之一:

对于 Crowdin:

  • 仅限我自己(即项目所有者)
  • 本人、项目管理员和开发者
  • 选定用户

对于 Crowdin Enterprise:

  • 仅限组织管理员
  • 组织管理员、项目管理员和开发者
  • 选定用户
manifest.json
{
"modules": {
"file-translations-alignment": [
{
"key": "your-translations-alignment-module-key",
"url": "/translations-alignment",
"signaturePatterns": {
"fileName": "^.+\.html$",
"fileContent": "<html.*>"
}
}
]
}
}
key

类型: string

必填:

描述: Crowdin 应用内的模块标识符。

url

类型: string

必填:

描述: 上传翻译时触发的相对 URL。

signaturePatterns

类型: object

描述: 包含 fileName 和/或 fileContent 正则表达式,用于在通过 UI 上传翻译(或通过 API 上传但未指定 type 参数)时检测文件类型。

上传非键值格式的翻译文件时,系统会使用 signaturePatterns 参数检测合适的翻译对齐模块。 然后,Crowdin 会向应用的 URL($baseUrl . $url)发出 HTTP 请求。

此请求包含两个主要数组:sourceStrings(来自项目)和 translationStrings(从上传的翻译文件中解析)。 应用的任务是处理这两组字符串,执行对齐,并返回将翻译映射到正确源字符串标识符的结构化响应。

请求载荷示例:

// max request payload - 5 MB
// wait timeout - 2 minutes
{
"jobType": "translation-alignment-file",
"organization": {
"id": 1,
"domain": "{domain}",
"baseUrl": "https://{domain}.crowdin.com",
"apiBaseUrl": "https://{domain}.api.crowdin.com"
},
"project": {
"id": 1,
"identifier": "your-project-identifier",
"name": "Your Project Name",
"userId": 1,
"sourceLanguageId": "en",
"targetLanguageIds": [
"ja",
"uk",
"et"
],
"createdAt": "2030-01-15T07:00:00+00:00",
"updatedAt": "2030-01-15T07:00:15+00:00",
"lastActivity": "2030-01-15T10:12:13+00:00",
"description": null,
"url": "/project/your-project-identifier",
"cname": null
},
"sourceLanguage": {
"id": "en",
"name": "English",
"editorCode": "en",
"twoLettersCode": "en",
"threeLettersCode": "eng",
"locale": "en-US",
"androidCode": "en-rUS",
"osxCode": "en.lproj",
"osxLocale": "en",
"pluralCategoryNames": [
"one",
"other"
],
"pluralRules": "(n != 1)",
"pluralExamples": [
"1",
"0, 2-999; 1.2, 2.07..."
],
"textDirection": "ltr",
"dialectOf": null
},
"targetLanguages": [
{
// Language object for the translation being aligned. Has the same structure as sourceLanguage.
}
],
"file": {
"id": 4219,
"name": "en.html",
"title": null,
"path": "/en.html",
"type": "html32",
"isMultilingual": false,
"status": "active",
"revision": 1,
"branchId": null,
"directoryId": 0
},
"sourceStrings": [
{
"id": 1234567,
"text": "Welcome!",
"context": "Document Title\r\nXPath: \/html\/head\/title"
}
// other source strings ...
],
"translationStrings": [
{
"id": null,
"text": "Ласкаво просимо!",
"context": "Document Title\r\nXPath: \/html\/head\/title"
}
// other translation strings ...
]
}

参数:

jobType

类型: string

值: translation-alignment-file

描述: 指定翻译对齐模块的操作。

file

类型: object

描述: 包含 Crowdin 中正在上传翻译的源文件的相关信息。

targetLanguages

类型: array

描述: 一个数组,包含正在上传和对齐的翻译文件的语言对象。

sourceStrings, sourceStringsUrl

类型(sourceStrings): array

类型(sourceStringsUrl): string

描述: 用于原始文件中源字符串的参数。 sourceStrings - 源字符串对象的数组。 sourceStringsUrl - 包含源字符串的 换行符分隔 JSON 文件的公共 URL。
可使用这两个参数中的任意一个。

translationStrings, translationStringsUrl

类型(translationStrings): array

类型(translationStringsUrl): string

描述: 用于从上传的翻译文件中解析的字符串的参数。 translationStrings - 简单字符串对象的数组。 translationStringsUrl - 包含翻译字符串的 换行符分隔 JSON 文件的公共 URL。
可使用这两个参数中的任意一个。

应用必须执行自定义对齐并返回包含 translations 数组的响应。 此数组将每个翻译文本映射到其对应的 sourceStringId

响应载荷示例:

// max response payload - 5 MB
// wait timeout - 2 minutes
{
"data": {
"translations": [
{
"sourceStringId": 1234567,
"text": "Ласкаво просимо!"
},
// other translation mappings...
],
// or use translationsUrl for large payloads
"translationsUrl": "https://app.example.com/jKe8ujs7a-aligned.ndjson" // new-line delimited json file with aligned translations
},
"error": {
"message": "Optional error message"
}
}

参数:

data.translations, data.translationsUrl

类型(data.translations): array

类型(data.translationsUrl): string

描述: 用于传递已对齐翻译的参数。 data.translations - 对齐对象的数组。 data.translationsUrl - 包含对齐对象的 换行符分隔 JSON 文件的公共 URL。
可使用这两个参数中的任意一个。

data.translations.sourceStringId

类型: integer

描述: 应用翻译的目标源字符串的数字标识符。

data.translations.text

类型: stringobject

描述: 要应用的翻译文本。 对于复数字符串,此项必须是以目标语言的复数类别名称(例如 oneother)为键的对象。

error.message

类型: string

描述: 可从应用传递至 Crowdin 的错误消息,将在 UI 中对用户可见。

本页面对你有帮助吗?