跳转到内容

自定义包生成器模块

使用此模块可支持目标文件包的自定义格式。 生成过程委托给实现了自定义包生成器模块的 Crowdin 应用。 当译文准备就绪后,Crowdin 会将译文数据发送至您的应用,应用以所需格式返回生成的包。

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

对于 Crowdin:

  • 仅限我自己(即项目所有者)
  • 所有项目成员
  • 选定用户

对于 Crowdin Enterprise:

  • 仅限组织管理员
  • 组织项目中的所有用户
  • 选定用户
manifest.json
{
"modules": {
"custom-file-format": [
{
"key": "your-module-key-type-xyz",
"type": "type-xyz",
"url": "/process",
"multilingualExport": true,
"stringsExport": true,
"extensions": [
".resx"
]
}
]
}
}
key

类型: string

必填:

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

type

类型: string

必填:

描述: 自定义包类型的标识符。 可在 API 中使用,以在生成翻译包时触发此模块的处理。

url

类型: string

必填:

描述: 在翻译导出期间触发的相对 URL。 Crowdin 向此 URL 发送请求以启动自定义包生成。

multilingualExport

类型: bool

必填:

允许值: truefalse。 默认值为 false

描述: 允许在单个请求中导出多个目标语言的字符串。 适用于在同一包中支持多种语言的文件格式。

stringsExport

类型: bool

必填:

描述: 对于包生成器模块,必须设置为 true。 表明应用期望从 Crowdin 导出字符串以生成自定义包。

extensions

类型: array

必填:

描述: 与生成的包关联的文件扩展名列表(例如 .resx.json)。 定义预期的输出格式,用于 Crowdin 中的文件命名和导出处理。

当用户请求导出翻译包时,Crowdin 会向应用配置的 URL($baseUrl . $url)发送包含必要项目、语言和译文数据的 HTTP 请求。 应用处理数据后,返回生成的包文件。

自定义包生成器应用的请求和响应具有两分钟超时限制。 请求和响应的最大负载大小限制为 5 MB。

请求载荷示例:

// max request payload - 5 MB
// wait timeout - 2 minutes
{
"jobType": "build-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"
},
"sourceLanguage": {
"id": "es",
"name": "Spanish",
"editorCode": "es",
"twoLettersCode": "es",
"threeLettersCode": "spa",
"locale": "es-ES",
"androidCode": "es-rES",
"osxCode": "es.lproj",
"osxLocale": "es",
"pluralCategoryNames": ["one"],
"pluralRules": "(n != 1)"
},
"targetLanguages": [
{
// same structure as for sourceLanguage
}
],
"strings": [...], // array of segments
"stringsUrl": "https://tmp.downloads.crowdin.com/strings.ndjson" // file with segments, in new-line delimited json format
}

参数:

jobType

类型: string

可能值: build-file

描述: 指定应用应执行的操作。 对于包生成器模块,始终设置为 build-file。 Crowdin 发送译文数据并期望返回生成的包。

strings, stringsUrl

类型(strings): array

类型(stringsUrl): string

描述: 包含用于包生成的翻译字符串。 可使用 strings(内联数组)或 stringsUrl(NDJSON 的公开链接)。


响应载荷示例:

// max response payload - 5 MB
// wait timeout - 2 minutes
{
"data": {
"content": "TWF5IHRoZSBGb3JjZSBiZSB3aXRoIHlvdS4=", // base64 encoded translation file content
"contentUrl": "https://app.example.com/p5uLEpq8p-result.xml", // translation file public URL
},
"error": {
"message": "Your error message"
}
}

参数:

data.content, data.contentUrl

类型(data.content): string

类型(data.contentUrl): string

描述: 使用 data.content(base64 编码)或 data.contentUrl(可公开访问的 URL)返回生成的包文件。 响应中只应包含其中一个。

文件格式取决于您的实现。

error.message

类型: string

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

以下是用于将翻译字符串传递给应用以生成自定义包的结构示例。

载荷示例:

// strings should be in "new-line delimited json" format if they passed by URL
[
{ // non plural string
"id": 1, // numeric identifier of the string in Crowdin
"identifier": "string-key-1", // required: unique string key
"context": "Some context", // optional: additional info for translators
"customData": "max 4 KB of custom data", // optional: preserved on export
"maxLength": 10, // optional, default null
"isHidden": false, // optional, default null
"hasPlurals": false, // optional, default false
"labels": ["label-one", "label-two"], // optional, default []
"text": "String source text", // required: source content
"translations": { // required: grouped by target language ID
"uk": { // targetLanguage.id
"text": "Переклад стрічки", // required: translation text
"status": "untranslated | translated | approved" // optional, default "translated"
},
// can be other languages for multilingual, check "targetLanguages" in the request payload
}
},
{ // plural string
"id": 2,
"identifier": "string-key-2",
"context": "Some optional context",
"customData": "max 4 KB of custom data",
"maxLength": 15,
"isHidden": false,
"hasPlurals": true,
"labels": [],
"text": { // keys from sourceLanguage.pluralCategoryNames
"one": "One file",
"other": "%d files",
},
"translations": {
"uk": {
"text": { // keys from targetLanguage.pluralCategoryNames
"one": "One file",
"few": "%d файла",
"many": "%d файлів",
},
"status": {
"one": "untranslated",
"few": "translated",
"many": "approved",
}
}
}
}
]

参数:

id

类型: integer

必填:

描述: 字符串在您的 Crowdin 项目中的数字标识符。 映射译文时必填。

identifier

类型: string

必填:

描述: 文件中的唯一字符串键。 必填。

text

类型: string(非复数)或 object(复数)

描述: 源字符串文本。 生成译文时必填。 对于复数字符串,这是一个以 sourceLanguage.pluralCategoryNames 中的复数形式键为键的对象。

customData

类型: string

必填:

描述: 需要关联到该字符串的任何自定义数据。 添加的自定义数据将在翻译导出时与对应字符串一起导出。

translations

类型: object

必填:

描述: 每种目标语言所需的译文。 每个语言 ID 映射到一个包含 text 字段以及可选 status 字段的对象。 对于复数字符串,textstatus 也是以复数类别名称为键的对象。

本页面对你有帮助吗?