Automatically patch translations with placeholders

fixes #630

// FREEBIE
This commit is contained in:
Sam Lanning 2016-01-22 09:29:49 +00:00 committed by lilia
parent df03f839b1
commit c5a9714a0a

View file

@ -197,8 +197,28 @@ module.exports = function(grunt) {
}
});
// Transifex does not understand placeholders, so this task patches all non-en
// locales with missing placeholders
grunt.registerTask('locale-patch', function(){
var en = grunt.file.readJSON('_locales/en/messages.json');
grunt.file.recurse('_locales', function(abspath, rootdir, subdir, filename){
if (subdir === 'en' || filename !== 'messages.json'){
return;
}
var messages = grunt.file.readJSON(abspath);
for (var key in messages){
if (en[key]['placeholders'] !== undefined && messages[key]['placeholders'] === undefined){
messages[key]['placeholders'] = en[key]['placeholders']
}
}
grunt.file.write(abspath, JSON.stringify(messages, null, 4) + '\n');
});
});
grunt.registerTask('dev', ['default', 'connect', 'watch']);
grunt.registerTask('test', ['jshint', 'jscs', 'connect', 'saucelabs-mocha']);
grunt.registerTask('default', ['concat', 'sass', 'copy']);
grunt.registerTask('default', ['concat', 'sass', 'locale-patch', 'copy']);
};