<commit_before>// TODO:
// 1) Check that the language matches before merge.
// 2) Pick up the language type for options!!
// 3) Output the result file
// 4) How to copy the comments also, not just the json content!!
// 5)

'use strict';

module.exports = function(grunt) {

    /**
     * Overwrites obj1's values with obj2's and adds obj2's if non existent in obj1
     * @param obj1
     * @param obj2
     * @returns obj3 a new object based on obj1 and obj2
     */
    function merge_options(obj1, obj2){
        var obj3 = {};
        for (var attrname in obj1) { obj3[attrname] = obj1[attrname]; }
        for (var attrname in obj2) { obj3[attrname] = obj2[attrname]; }
        return obj3;
    }

    // table running total of entries
    var runningTotal;

    function example(filepath, options) {

        console.log("This is my example grunt task!!");
        console.log(filepath);
        //console.log(options);
        var obj = grunt.file.readJSON(filepath);

        if (obj) {
            if (obj.language === 'en') {
                if (runningTotal) {
                    var result = merge_options(runningTotal.table, obj.table);
                    runningTotal.table = result;
                }
                else
                {
                    console.log("Total setup now........");
                    runningTotal = obj;
                }
            }
            else {
                console.log('Error: file found containing language which does not match!!');
            }
        }
    }

    grunt.task.registerMultiTask('example', 'Build Locale files.', function () {

        var options = this.options({
            force: grunt.option('force') === true,
            'no-write': grunt.option('no-write') === true
        });

        grunt.verbose.writeflags(options, 'Options');


        this.filesSrc.forEach(function(filepath) {
            example(filepath, options);
        });

        // TODO: pick this up from the grunt configuration file
        var outputFile = "c:/typhoon/webServer/build/release/en.json";

        if (runningTotal) {
            grunt.file.write(outputFile, JSON.stringify(runningTotal));
        }
    });

}<commit_msg>Some minor changes. - display options - change task name (still not happy with it!!)<commit_after>// TODO:
// 1) Check that the language matches before merge.
// 2) Pick up the language type for options!!
// 3) Output the result file
// 4) How to copy the comments also, not just the json content!!
// 5)

'use strict';

module.exports = function(grunt) {

    /**
     * Overwrites obj1's values with obj2's and adds obj2's if non existent in obj1
     * @param obj1
     * @param obj2
     * @returns obj3 a new object based on obj1 and obj2
     */
    function mergeTranslations(obj1, obj2){
        var obj3 = {};
        for (var attrname in obj1) { obj3[attrname] = obj1[attrname]; }
        for (var attrname in obj2) { obj3[attrname] = obj2[attrname]; }
        return obj3;
    }

    // table running total of entries
    var runningTotal;

    function merge(filepath, options) {

        console.log("This is my angular-translate-merge grunt task!!");
        console.log(filepath);
        console.log(options);

        var obj = grunt.file.readJSON(filepath);

        if (obj) {
            if (obj.language === options.language) {
                if (runningTotal) {
                    runningTotal.table = mergeTranslations(runningTotal.table, obj.table);
                }
                else
                {
                    console.log("Total setup now........");
                    runningTotal = obj;
                }
            }
            else {
                console.log('Error: file found containing language which does not match!!');
            }
        }
    }

    grunt.task.registerMultiTask('mergeAngularTranslate', 'Build Locale files.', function () {

        var options = this.options({
            force: grunt.option('force') === true,
            'no-write': grunt.option('no-write') === true
        });

        grunt.verbose.writeflags(options, 'Options');


        this.filesSrc.forEach(function(filepath) {
            merge(filepath, options);
        });

        // TODO: pick this up from the grunt configuration file
        var outputFile = "c:/typhoon/webServer/build/release/en.json";

        if (runningTotal) {
            grunt.file.write(outputFile, JSON.stringify(runningTotal));
        }
    });

}
{'fraction_non_alphanumeric': 0.11877651261442286, 'fraction_numerical': 0.010716677829872739, 'mean_word_length': 1.8498727735368956, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3201237', 'n_tokens_mistral': 1285, 'n_tokens_neox': 1221, 'n_words': 355}