Skip to content

File Pre-Import Processing Module

The pre-import module allows you to modify your files before importing them to Crowdin. With the pre-import module, you can apply automated modifications to selected files. This module can work with a wide range of file formats, such as TXT, XML, JSON, and many more, to customize their contents.

By using the pre-import module in your Crowdin app, you can adjust the file format, structure, and content. Since the module is executed before Crowdin imports the file, you can fine-tune the content before the file is processed by the system.

Access

You can grant access to this module to one of the following user categories:

For Crowdin:

  • Only me (i.e., project owner)
  • All project members
  • Selected users

For Crowdin Enterprise:

  • Only organization admins
  • All users in the organization projects
  • Selected users

Structure

manifest.json
{
"modules": {
"file-pre-import": [
{
"key": "your-pre-import-module-key",
"url": "/import-file",
"signaturePatterns": {
"fileName": "^.+\\.xml$",
"fileContent": "<properties>\\s*<property\\s+name=.*value=.*/>"
}
}
]
}
}

Properties

key

Type: string

Required: yes

Description: Module identifier within the Crowdin app.

url

Type: string

Required: yes

Description: The relative URL triggered on file import, update, and translation upload.

signaturePatterns

Type: object

Description: Contains fileName and/or fileContent regular expressions used to detect file type when uploading a new source file via UI (or via API without specified type parameter).

Communication between File Processing App and Crowdin

When importing a file, Crowdin detects an appropriate module using the signaturePatterns parameter and makes an HTTP request to the app’s URL ($baseUrl . $url) for further processing.

Additionally, during the file import, Crowdin will also validate the file name and content to ensure they match the appropriate file processing app modules. This process can include the pre-import processing module to modify the content of the file before it is imported and the post-import processing module to modify the strings extracted from the file.

To modify the file content, the system first locates the appropriate pre-import module and sends the file content to it. The module then performs the predetermined modifications, which may include file format changes, structure, and content updates.

Once the pre-import module has completed the file modifications, Crowdin receives the modified file content, as well as a new file name or extension if applicable.

Request to the File Processing App

Request payload example:

// max request payload - 5 MB
// wait timeout - 2 minutes
{
"jobType": "file-pre-import",
"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, can be more for multilingual files
}
]
}

Properties:

jobType

Type: string

Value: file-pre-import

Description: Specifies the action of the file pre-import module.

file.content, file.contentUrl

Type: string

Description: Parameters used to pass the base64 encoded source file content (file.content) or a source file public URL (file.contentUrl).
Either of these two parameters can be used.

Expected Response from the App

Response payload example:

// max response payload - 5 MB
// wait timeout - 2 minutes
{
"data": {
"content": "VGhpcyBpcyBmaWxlIGNvbnRlbnQ=", // base64 encoded modified file content
"contentUrl": "https://crowdin-tmp.downloads.crowdin.com/1/file.xml?aws-signature=...", // modified file public URL
"fileName": "file.html", // optional, new file name with extension
"fileType": "webxml" // optional, an importer Crowdin should use to import a file
},
"error": {
"message": "Your error message"
}
}

Properties:

data.content, data.contentUrl

Type(data.content): string

Type(data.contentUrl): string

Description: Parameters used to pass the base64 encoded modified file content (data.content) or a modified file public URL (data.contentUrl).
Either of these two parameters can be used.

fileName

Type: string

Description: Optional parameter used to overwrite a file name and extension with a new one.

fileType

Type: string

Description: Optional parameter to specify an importer Crowdin should use to import a file.

error.message

Type: string

Description: An error message that can be passed from the app to Crowdin and will be visible to a user in the UI.

Was this page helpful?