これが私がやり終えたことであり、私の問題を解決したものです。タスク構成については、次のことを行いました。
grunt.initConfig({
convert_po: {
build: {
src: 'C:/temp/Locale/*.po',
dest: 'C:/temp/Locale/output/'
}
}
});
そして、これはタスクの実装です:
grunt.registerMultiTask('convert_po', 'Convert PO files to JSON format', function() {
var po = require('node-po');
var path = require('path');
grunt.log.write('Loaded dependencies...').ok();
//make grunt know this task is async.
var done = this.async();
var i =0;
this.files.forEach(function(file) {
grunt.log.writeln('Processing ' + file.src.length + ' files.');
//file.src is the list of all matching file names.
file.src.forEach(function(f){
//this is an async function that loads a PO file
po.load(f, function(_po){
strings = {};
for (var idx in _po.items){
var item = _po.items[idx];
strings[item.msgid] = item.msgstr.length == 1 ? item.msgstr[0] : item.msgstr;
}
var destFile = file.dest + path.basename(f, '.po') + '.json';
grunt.log.writeln('Now saving file:' + destFile);
fs.writeFileSync(destFile, JSON.stringify(strings, null, 4));
//if we processed all files notify grunt that we are done.
if( i >= file.src.length) done(true);
});
});
});
});