lib/main.js
function(data, onProgress) {
        onProgress = onProgress || function() {};
        return new Promise(function(resolve, reject) {
            try {
                let obj = JSON.parse(data);
                _.forEach(obj.languages, function (questionnaire, index) {
                    // format
                    questionnaire.language_slug = questionnaire.slug;
                    questionnaire.language_name = questionnaire.name;
                    questionnaire.td_id = questionnaire.questionnaire_id;
                    questionnaire.language_direction = questionnaire.dir.toLowerCase() === 'rtl' ? 'rtl' : 'ltr';

                    try {
                        let id = library.addQuestionnaire(questionnaire);
                        if (id > 0) {
                            // add questions
                            _.forEach(questionnaire.questions, function (question, n) {
                                // format question
                                question.is_required = question.required ? 1 : 0;
                                question.depends_on = question.depends_on === null ? -1 : question.depends_on;
                                question.td_id = question.id;

                                try {
                                    library.addQuestion(question, id);
                                } catch (err) {
                                    console.error('Failed to add question', question);
                                    reject(err);
                                    return;
                                }
                                // broadcast itemized progress if there is only one questionnaire
                                if (obj.languages.length == 1) {
                                    onProgress(questionnaire.questions.length, n + 1);
                                }
                            });
                        } else {
                            console.error('Failed to add questionnaire', questionnaire);
                        }
                    } catch (err) {
                        console.error('Failed to add questionnaire', questionnaire);
                        reject(err);
                        return;
                    }
                    // broadcast overall progress if there are multiple questionnaires.
                    if (obj.languages.length > 1) {
                        onProgress(obj.languages.length, index + 1);
                    }
                });
                resolve();
            } catch (err) {
                reject(err);
            }
        });
    }
function(data, onProgress) {
        onProgress = onProgress || function() {};
        return new Promise(function(resolve, reject) {
            try {
                let obj = JSON.parse(data);
                _.forEach(obj.languages, function (questionnaire, index) {
                    // format
                    questionnaire.language_slug = questionnaire.slug;
                    questionnaire.language_name = questionnaire.name;
                    questionnaire.td_id = questionnaire.questionnaire_id;
                    questionnaire.language_direction = questionnaire.dir.toLowerCase() === 'rtl' ? 'rtl' : 'ltr';

                    try {
                        let id = library.addQuestionnaire(questionnaire);
                        if (id > 0) {
                            // add questions
                            _.forEach(questionnaire.questions, function (question, n) {
                                // format question
                                question.is_required = question.required ? 1 : 0;
                                question.depends_on = question.depends_on === null ? -1 : question.depends_on;
                                question.td_id = question.id;

                                try {
                                    library.addQuestion(question, id);
                                } catch (err) {
                                    console.error('Failed to add question', question);
                                    reject(err);
                                    return;
                                }
                                // broadcast itemized progress if there is only one questionnaire
                                if (obj.languages.length == 1) {
                                    onProgress(questionnaire.questions.length, n + 1);
                                }
                            });
                        } else {
                            console.error('Failed to add questionnaire', questionnaire);
                        }
                    } catch (err) {
                        console.error('Failed to add questionnaire', questionnaire);
                        reject(err);
                        return;
                    }
                    // broadcast overall progress if there are multiple questionnaires.
                    if (obj.languages.length > 1) {
                        onProgress(obj.languages.length, index + 1);
                    }
                });
                resolve();
            } catch (err) {
                reject(err);
            }
        });
    }
function ( data , onProgress ) { onProgress = onProgress || function ( ) { } ; return new Promise ( function ( resolve , reject ) { try { let obj = JSON . parse ( data ) ; _ . forEach ( obj . languages , function ( questionnaire , index ) { // format questionnaire . language_slug = questionnaire . slug ; questionnaire . language_name = questionnaire . name ; questionnaire . td_id = questionnaire . questionnaire_id ; questionnaire . language_direction = questionnaire . dir . toLowerCase ( ) === 'rtl' ? 'rtl' : 'ltr' ; try { let id = library . addQuestionnaire ( questionnaire ) ; if ( id > 0 ) { // add questions _ . forEach ( questionnaire . questions , function ( question , n ) { // format question question . is_required = question . required ? 1 : 0 ; question . depends_on = question . depends_on === null ? - 1 : question . depends_on ; question . td_id = question . id ; try { library . addQuestion ( question , id ) ; } catch ( err ) { console . error ( 'Failed to add question' , question ) ; reject ( err ) ; return ; } // broadcast itemized progress if there is only one questionnaire if ( obj . languages . length == 1 ) { onProgress ( questionnaire . questions . length , n + 1 ) ; } } ) ; } else { console . error ( 'Failed to add questionnaire' , questionnaire ) ; } } catch ( err ) { console . error ( 'Failed to add questionnaire' , questionnaire ) ; reject ( err ) ; return ; } // broadcast overall progress if there are multiple questionnaires. if ( obj . languages . length > 1 ) { onProgress ( obj . languages . length , index + 1 ) ; } } ) ; resolve ( ) ; } catch ( err ) { reject ( err ) ; } } ) ; }
Parses the new language questions catalog and indexes it.

@param data {string}
@param onProgress {function} an optional progress listener. This should receive progress id, total, completed
@returns {Promise}
Parses the new language questions catalog and indexes it .