<commit_before>/*
 * grunt-gettext-checker
 *
 *
 * Copyright (c) 2014 Incuna Ltd.
 * Licensed under the MIT license.
 */

'use strict';

module.exports = function (grunt) {

    grunt.registerMultiTask('gettext-checker', 'Compares .pot and .po file translation to check for differences', function () {

        // import Nodejs libs
        var _ = require('lodash');
        var poLib = require('pofile');

        // Get task options and merge with defaults
        var defaultOptions = {
            checkPoKeys: true,
            checkPotKeys: true,
            checkKeyOrder: true,
            templateFile: 'i18n/template.pot',
            poFile: 'i18n/en-gb.po'
        };
        var options = this.options(defaultOptions);

        var checkFileExists = function (path) {
            if (!grunt.file.isFile(path)) {
                grunt.fail.fatal(path + ' does not exist');
            }
        };

        var getPoKeys = function (items) {
            return _.map(items, function (item) {
                return item.msgid;
            });
        };

        var validatePoFile = function (poObject, filePath) {
            if (!poObject.headers) {
                grunt.fail.fatal(filePath + ' can not be loaded. Check the file is a valid .po file');
            }
        };

        var error = false;

        var checkPoFile = function (poFilePath, templateFile, potKeys) {
            // load .po file
            checkFileExists(poFilePath);
            var poFileSource = grunt.file.read(poFilePath);
            var poFile = poLib.parse(poFileSource);

            validatePoFile(poFile, poFilePath);

            // get po file keys as array
            var poKeys = getPoKeys(poFile.items);

            grunt.log.writeln('Checking files: ' + options.templateFile + '->' + poFilePath);

            var keyDiff;

            if (options.checkPoKeys) {
                // find items in template.pot that are not in this po file<commit_msg>Undo function move<commit_after>/*
 * grunt-gettext-checker
 *
 *
 * Copyright (c) 2014 Incuna Ltd.
 * Licensed under the MIT license.
 */

'use strict';

module.exports = function (grunt) {

    grunt.registerMultiTask('gettext-checker', 'Compares .pot and .po file translation to check for differences', function () {

        // import Nodejs libs
        var _ = require('lodash');
        var poLib = require('pofile');

        // Get task options and merge with defaults
        var defaultOptions = {
            checkPoKeys: true,
            checkPotKeys: true,
            checkKeyOrder: true,
            templateFile: 'i18n/template.pot',
            poFile: 'i18n/en-gb.po'
        };
        var options = this.options(defaultOptions);

        var checkFileExists = function (path) {
            if (!grunt.file.isFile(path)) {
                grunt.fail.fatal(path + ' does not exist');
            }
        };

        var validatePoFile = function (poObject, filePath) {
            if (!poObject.headers) {
                grunt.fail.fatal(filePath + ' can not be loaded. Check the file is a valid .po file');
            }
        };

        var getPoKeys = function (items) {
            return _.map(items, function (item) {
                return item.msgid;
            });
        };

        var error = false;

        var checkPoFile = function (poFilePath, templateFile, potKeys) {
            // load .po file
            checkFileExists(poFilePath);
            var poFileSource = grunt.file.read(poFilePath);
            var poFile = poLib.parse(poFileSource);

            validatePoFile(poFile, poFilePath);

            // get po file keys as array
            var poKeys = getPoKeys(poFile.items);

            grunt.log.writeln('Checking files: ' + options.templateFile + '->' + poFilePath);

            var keyDiff;

            if (options.checkPoKeys) {
                // find items in template.pot that are not in this po file
{'fraction_non_alphanumeric': 0.1045950748921046, 'fraction_numerical': 0.004061944656004062, 'mean_word_length': 1.768798313422347, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '780430', 'n_tokens_mistral': 1120, 'n_tokens_neox': 1061, 'n_words': 297}