# Custom Pre-Export Processor

> This application allows you to process translated strings before exporting with custom code.

URL: https://store.crowdin.com/custom-pre-export-processor
Identifier: custom-pre-export-processor
Category: Development, File Formats
Type: App
Author: Awesome Crowdin

This application allows you to process translated strings before writing them into the translated resource file with your own JavaScript code.

## Coding
JavaScript code is executed in a sandboxed environment with no access to I/O (file system, network) or external NPM modules.

This app will expose the following variables in the global environment: 
 - `strings` - an array of objects containing all strings Crowdin identified as translatable. Please refer to the [Developer Portal](https://developer.crowdin.com/crowdin-apps-module-file-post-import-processing/#:~:text=the%20app%20response.-,Payload%20example%3A,-content_copy) to learn more about the data structures.
 - `fileName` - the name of the uploaded file;
 - `projectId` - Crowdin project ID;
 - `languageId` - Target language Crowdin ID;
 - `error` - the error message you want to return. If set, the import will be aborted and the error message will be shown to the user;

Edit string properties inside the `strings` array to introduce changes you need.

## Example application

Replace `Product` with `SUPER`
```javascript
for(const string of strings) {
    string.translations[languageId].text = string.translations[languageId].text.replace('Product', 'SUPER!');
}
```

In JSON files, set the value to empty string for all untranslated strings.
```javascript
if (fileName.endsWith('.json')) {
    for (const string of strings) {
        if (string.translations[languageId].status == 'untranslated') {
            string.translations[languageId].text = '';
        }
    }
}
```


## Installation and Setup

1. **Install App.** During installation, select **All projects** or **Selected projects** for the app's access.

2. **Navigate to File Processors.** Go to **Project Settings → File Processors** within an installed project.

3. **Insert and Submit Code.** Click on the processor, insert your custom JavaScript code, and click **Submit** to save it.

## Screenshots

![](https://developers.app.crowdin.net/api/media/file/8002533d-fa2d-4fbb-addb-49714d11e74a.png)
![](https://developers.app.crowdin.net/api/media/file/516a1f23-7820-49c7-946c-8622da9ae3dc.png)
