# Custom Bundle Generator

> The app allows you to generate a resource files out of translate Crowdin strings.

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

This app allows you to create your own simple bundle generator using JavaScript. 

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

This application will expose the following variables in the global environment: 
 - `strings` - an array of objects containing all strings that Crowdin has identified as translatable. Please refer to the [Developer Portal](https://developer.crowdin.com/crowdin-apps-module-custom-file-format/) to learn more about the data structures.
 - `projectId` - the Crowdin project ID;
 - languageId' - target language Crowdin ID;
 - `error` - the error message to return. If set, the import will be aborted and the error message will be shown to the user;
 - `code` - this variable should contain the content (string) of the file to be exported after your code is executed;

## Example application

```javascript
const result = strings.map(s => {
    return {
        id: s.identifier,
        text: s.translations[languageId].text
    }
})

content = JSON.stringify(result);
```

a JSON with plurals serialized for Vue i18n lib
```javascript
let result = {};

strings.map(s => {
    if (s.hasPlurals) {
        result[s.identifier] = Object.values(s.translations[languageId].text).join(' | ');
    } else {
        result[s.identifier] = s.translations[languageId].text;
    }
});

content = JSON.stringify(result);
```

This code exports strings as JSON, an array of objects with two properties, `id` and `text`.

## Screenshot
![](https://developers.app.crowdin.net/api/media/file/194ea655-e57b-488f-92fa-d6e91252da2c.png)
