Skip to content

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.

Sample

index.js
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
filesFolderFolder where large files are temporarily stored.
signaturePatternsContains fileName and/or fileContent regular expressions used to detect file type when uploading a new source file via UI or API.
processAssetsSet 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 to true 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.