自定义文件格式模块
使用此模块添加新自定义文件格式的支持。 它通过将源文件解析委托给带有自定义文件格式模块的应用程序来实现。 翻译完成后,Crowdin 会将源文件和包含翻译的字符串数组传递给自定义文件格式应用程序,以便生成翻译文件。
您可以将此模块的访问权限授予以下用户类别之一:
对于 Crowdin:
- 仅限我自己(即项目所有者)
- 所有项目成员
- 选定用户
对于 Crowdin Enterprise:
- 仅限组织管理员
- 组织项目中的所有用户
- 选定用户
{ "modules": { "custom-file-format": [ { "key": "your-module-key-type-xyz", "type": "type-xyz", "url": "/process", "multilingual": true, "signaturePatterns": { "fileName": "^.+\.xyz$", "fileContent": "<properties>\s*<property\s+name=.*value=.*/>" } } ] }}key | 类型: 必填: 是 描述: Crowdin 应用内的模块标识符。 |
type | 类型: 必填: 是 描述: 自定义文件格式标识符。 可在 API 中使用,以强制通过自定义文件格式应用程序处理文件。 如果在 API 中使用了 |
url | 类型: 必填: 是 描述: 在文件导入、更新、翻译上传和导出时触发的相对 URL。 |
multilingual | 类型: 必填: 否 允许值: 描述: 此参数用于在上传和下载 Crowdin 项目中的翻译时,将多种语言的内容合并到一个请求中。 |
signaturePatterns | 类型: 描述: 包含 |
在初始文件导入时,系统使用 signaturePatterns 或 type 参数检测自定义文件格式,并向应用程序的 URL($baseUrl)发出 HTTP 请求。 $url)发送 HTTP 请求以进行进一步处理。 然后应用程序以自定义格式处理文件并响应系统。 与自定义文件格式应用程序之间的请求和响应具有两分钟超时限制。 请求和响应的最大负载大小限制为 5 MB。
请求载荷示例:
// max request payload - 5 MB// wait timeout - 2 minutes{ "jobType": "parse-file | 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" }, "file": { "id": 1, "name": "file.xml", "content": "VGhpcyBpcyBmaWxlIGNvbnRlbnQ=", // base64 encoded source file content "contentUrl": "https://crowdin-tmp.downloads.crowdin.com/1/file.xml?aws-signature=..." // source file public URL }, "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, empty when uploading a new source file, one element for import_translations & export, can be more for multilingual files } ], "strings": [...], // for the build-file jobs, array of segments "stringsUrl": "https://tmp.downloads.crowdin.com/strings.ndjson" // for the build-file jobs, file with segments, in new-line delimited json format}参数:
jobType | 类型: 可选值: 描述: 指定应由应用程序执行的操作。 |
file.content, file.contentUrl | 类型: 说明: 用于传递 base64 编码的源文件内容( |
strings, stringsUrl | 类型(strings): 类型(stringsUrl): 描述: 用于翻译下载的参数(仅适用于 |
响应载荷示例:
// max response payload - 5 MB// wait timeout - 2 minutes{ "data": { "strings": [...], // segments array "stringsUrl": "https://app.example.com/jKe8ujs7a-segments.ndjson", // new-line delimited json file with parsed strings "preview": "VGhpbmdzIGFyZSBvbmx5IGltcG9zc2libGUgdW50aWwgdGhleSdyZSBub3Qu", // optional, base64 encoded content of preview html file, not supported if there are plural strings "previewUrl": "https://app.example.com/LN3km2K6M-preview.html", // optional, URL of preview html file, not supported if there are plural strings }, "error": { "message": "Your error message" }}参数:
data.strings, data.stringsUrl | 类型(data.strings): 类型(data.stringsUrl): 描述: 用于传递已解析字符串内容的参数。 |
data.preview, data.previewUrl | 类型(data.preview): 类型(data.previewUrl): 说明: 用于传递可由应用生成的已解析字符串内容的可选 HTML 预览的参数。 生成的 HTML 预览将在编辑器中显示。 请参阅 HTML 预览文件示例。 |
error.message | 类型: 描述: 可从应用程序传递给 Crowdin Enterprise 的错误消息,将在 UI 中对用户可见。 |
响应载荷示例:
// 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): 描述: 用于传递 base64 编码翻译文件内容( |
error.message | 类型: 描述: 可从应用程序传递给 Crowdin Enterprise 的错误消息,将在 UI 中对用户可见。 |
以下是应用程序针对 parse-file 任务类型所期望的字符串结构示例,以及传递给应用程序用于 build-file 任务类型的字符串结构示例。
载荷示例:
// strings should be in "new-line delimited json" format if they passed by URL[ { // non plural string "previewId": 1, // only for "parse-file" jobType, required when the HTML preview of the file is generated "id": 1, // only for "build-file" jobType "identifier": "string-key-1", // required "context": "Some context", // optional "customData": "max 4 KB of custom data", // optional "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 "translations": { // optional "uk": { // targetLanguage.id "text": "Переклад стрічки", // required "status": "untranslated | translated | approved" // optional, default "translated" }, // can be other languages for multilingual, check "targetLanguages" in the request payload } }, { // plural string "previewId": 2, "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", } } } }]参数:
previewId | 类型: 必填: 是(仅当 描述: HTML 预览文件中字符串的数字标识符。 仅用于 |
id | 类型: 描述: 字符串在 Crowdin Enterprise 项目中的数字标识符。 仅用于 |
identifier | 类型: 描述: 文件内唯一的字符串键。 |
customData | 类型: 描述: 需要与字符串关联的任意自定义数据。 添加的自定义数据将在翻译导出时与对应字符串一起导出。 |
文件 HTML 预览示例:
<html lang="en"> <head> <title>Optional Title</title> <style> table, th, td { border: 1px solid #aaa; } </style> </head> <body> <h1 style="text-align: center">HTML preview of the file</h1> <table style="width: 100%"> <tr> <th>Key:</th> <th>Text:</th> </tr> <tr> <td>Key 1</td> <td><span id="string_preview_id_1">Source Text 1</span></td> <!-- 1 is previewId in strings json --> </tr> <tr> <td>Key 2</td> <td><span id="string_preview_id_2">Source Text 2</span></td> <!-- 2 is previewId in strings json --> </tr> </table> </body></html>