File Pre-Import
Pre-import Apps allow you to modify your files before importing them into Crowdin. With the Pre-Import App, you can make automated changes to selected files.
File Pre-Import Processing Module Read more on the Crowdin Developer Portal.
Sample
const crowdinModule = require('@crowdin/app-project-module');
const configuration = { baseUrl: 'https://123.ngrok.io', clientId: 'clientId', clientSecret: 'clientSecret', name: 'Sample App', identifier: 'sample-app', description: 'Sample App description', dbFolder: __dirname, imagePath: __dirname + '/' + 'logo.png', filePreImport: { filesFolder: `${__dirname}/db`, signaturePatterns: { fileName: "^.+\\..+$", fileContent: ".*" }, fileProcess: async (req, contentFile, client, context, projectId) => { const fileName = 'newFileName.txt'; contentFile = Buffer.from( contentFile.toString().replace('<text-to-replace>','<content>') ); return { contentFile, fileName }; } }};
crowdinModule.createApp(configuration);
Configuration
Parameter | Description |
---|---|
filesFolder | Folder where large files are temporarily stored. |
signaturePatterns | Contains fileName and/or fileContent regular expressions used to detect file type when uploading a new source file via UI or API. |
processAssets | Set to true to enable processing of assets (e.g., images, videos) within the application. By default, assets are not processed. |
fileProcess
Function
This function is called for each file that is imported to Crowdin.
Parameters
req
- Request object.contentFile
- File content.client
- Crowdin API client.context
- Context object.projectId
- Crowdin project ID.
Return Value
The function should return the following object:
{ contentFile: Buffer | string, fileName?: string, notModified?: boolean, error?: string}
Description:
contentFile
- should contain the modified file content.fileName
- optional, should contain the new file name if the file processor changes the file name.notModified
- optional, should be set totrue
if the file processor does not make any changes to the file.error
- optional, should contain an error message if the file processor encounters an error.