Custom Bundle Generator FreeBeta
ByAwesome CrowdinVerified Author

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

Install

Custom bundle generator: Create resource files from Crowdin strings

Copy link

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

Coding

Copy link

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 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

Copy link
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

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

Copy link

Screenshot

Crowdin is a platform that helps you manage and translate content into different languages. Integrate Crowdin with your repo, CMS, or other systems. Source content is always up to date for your translators, and translated content is returned automatically.

Learn More
Categories
Development
File Formats
Works with
  • Crowdin Enterprise
  • crowdin.com
Details

Released on Sep 23, 2023

Updated on Jul 30, 2024

Published by Awesome Crowdin

Identifier:custom-bundle-generator