自定义包生成器模块
使用此模块可支持目标文件包的自定义格式。 生成过程委托给实现了自定义包生成器模块的 Crowdin 应用。 当译文准备就绪后,Crowdin 会将译文数据发送至您的应用,应用以所需格式返回生成的包。
您可以将此模块的访问权限授予以下用户类别之一:
对于 Crowdin:
- 仅限我自己(即项目所有者)
- 所有项目成员
- 选定用户
对于 Crowdin Enterprise:
- 仅限组织管理员
- 组织项目中的所有用户
- 选定用户
{ "modules": { "custom-file-format": [ { "key": "your-module-key-type-xyz", "type": "type-xyz", "url": "/process", "multilingualExport": true, "stringsExport": true, "extensions": [ ".resx" ] } ] }}key | 类型: 必填: 是 描述: Crowdin 应用内的模块标识符。 |
type | 类型: 必填: 是 描述: 自定义包类型的标识符。 可在 API 中使用,以在生成翻译包时触发此模块的处理。 |
url | 类型: 必填: 是 描述: 在翻译导出期间触发的相对 URL。 Crowdin 向此 URL 发送请求以启动自定义包生成。 |
multilingualExport | 类型: 必填: 否 允许值: 描述: 允许在单个请求中导出多个目标语言的字符串。 适用于在同一包中支持多种语言的文件格式。 |
stringsExport | 类型: 必填: 是 描述: 对于包生成器模块,必须设置为 |
extensions | 类型: 必填: 是 描述: 与生成的包关联的文件扩展名列表(例如 |
当用户请求导出翻译包时,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 | 类型: 可能值: 描述: 指定应用应执行的操作。 对于包生成器模块,始终设置为 |
strings, stringsUrl | 类型(strings): 类型(stringsUrl): 描述: 包含用于包生成的翻译字符串。 可使用 |
响应载荷示例:
// 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): 类型(data.contentUrl): 描述: 使用 文件格式取决于您的实现。 |
error.message | 类型: 描述: 可从应用传递至 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 | 类型: 必填: 是 描述: 字符串在您的 Crowdin 项目中的数字标识符。 映射译文时必填。 |
identifier | 类型: 必填: 是 描述: 文件中的唯一字符串键。 必填。 |
text | 类型: 描述: 源字符串文本。 生成译文时必填。 对于复数字符串,这是一个以 |
customData | 类型: 必填: 否 描述: 需要关联到该字符串的任何自定义数据。 添加的自定义数据将在翻译导出时与对应字符串一起导出。 |
translations | 类型: 必填: 是 描述: 每种目标语言所需的译文。 每个语言 ID 映射到一个包含 |