rockykitamura / grunt-po2json

MIT License
16 stars 21 forks source link

Add two new options, `output_filename` and `output_transform` #6

Open shane-tomlinson opened 10 years ago

shane-tomlinson commented 10 years ago

output_filename allows the caller to customize the output filename. Function is passed the source filename and returns an output filename. If no value is returned, default behavior is used.

  options: {
    output_filename: function(file) {
      // only rename en.po. All other files use default behavior.
      if (/en\.po/.test(file)) {
        return 'english.json';
      }
    }
  }

output_transform allows the caller to transform the output before it is written to a file.

  options: {
    output_transform: function(data) {
      var isArray = function(item) {
        return Object.prototype.toString.call(translation)
                        === "[object Array]";
      }

      var transformed = {};
      for (var msgid in data) {
        var translation = data[msgid];
        if (isArray(translation) && translation.length >= 2) {
          // use the first translation only, no pluralization.
          translation = translation[1];
        }

        transformed[msgid] = translation;
      }

      return transformed;
    }
  }
zaach commented 10 years ago

@rkitamura Hi! Could you take a look at this PR? We're using it in our project to great affect: https://github.com/mozilla/fxa-content-server/blob/master/grunttasks/po2json.js#L18

vladikoff commented 10 years ago

Hey @shane-tomlinson, seems like @rockykitamura gave you contrib rights to this repo, should we rebase this?

ydaniv commented 8 years ago

@rockykitamura @shane-tomlinson @vladikoff any chance merging these PR's?