var po = require('pofile');
var _ = require('lodash');

var formats = {
    javascript: {
        addLocale: function(locale, strings) {
            return "    gettextCatalog.setStrings('" + locale + "', " + JSON.stringify(strings) + ");\n";
        },
        format: function(locales, options) {
            var module = "angular.module('" + options.module + "').run(['gettextCatalog', function (gettextCatalog) {\n/* jshint -W100 */\n" + locales.join('') + "/* jshint +W100 */\n}]);";
            if (options.requirejs) {
                return "define(['angular', '" + options.modulePath + "'],function(angular){\n" + module + "\n});";
            }

            return module;
        }
    },
    json: {
        addLocale: function(locale, strings) {
            return {
                name: locale,
                strings: strings
            };
        },
        format: function(locales, options) {
            var result = {};
            locales.forEach(function(locale) {
                result[locale.name] = locale.strings;
            });
            return JSON.stringify(result);
        }
    }
};

var Compiler = (function() {
    function Compiler(options) {
        this.options = _.extend({
            format: 'javascript',
            module: 'gettext'
        }, options);
    }

    Compiler.hasFormat = function(format) {
        return formats.hasOwnProperty(format);
    };

    Compiler.prototype.convertPo = function(inputs) {
        var format = formats[this.options.format];
        var locales = [];

        inputs.forEach(function(input) {
            var catalog = po.parse(input);

            if (!catalog.headers.Language) {
                throw new Error('No Language header found!');
            }

            var strings = {};
            for (var i = 0; i < catalog.items.length; i++) {
                var item = catalog.items[i];
                if (item.msgstr[0].length > 0) {
                    strings[item.msgid] = item.msgstr.length === 1 ? item.msgstr[0] : item.msgstr;
                }
            }

            locales.push(format.addLocale(catalog.headers.Language, strings));

        });

        return format.format(locales, this.options);
    };

    return Compiler;
})();

module.exports = Compiler;
@@ -102,32 +102,33 @@
 Locale: function
+ 
 (locale, strings
@@ -264,32 +264,33 @@
 format: function
+ 
 (locales, option
@@ -730,24 +730,25 @@
 le: function
+ 
 (locale, str
@@ -885,24 +885,25 @@
 at: function
+ 
 (locales, op
@@ -976,16 +976,17 @@
 function
+ 
 (locale)
@@ -1145,16 +1145,17 @@
 function
+ 
 () %7B%0A   
@@ -1343,16 +1343,17 @@
 function
+ 
 (format)
@@ -1449,24 +1449,25 @@
 o = function
+ 
 (inputs) %7B%0A 
@@ -1574,16 +1574,17 @@
 function
+ 
 (input) 

Fix CI build