2016-06-07 06:46:45 +00:00
|
|
|
var fs = require('fs');
|
2016-05-03 14:23:31 +00:00
|
|
|
var path = require('path');
|
2016-06-07 06:46:45 +00:00
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
var {
|
|
|
|
uniqueBy,
|
|
|
|
sortBy
|
|
|
|
} = require('min-dash');
|
|
|
|
|
2016-05-03 14:23:31 +00:00
|
|
|
|
2016-06-07 06:46:45 +00:00
|
|
|
function TranslationReporter() {
|
|
|
|
process.env.TRANSLATIONS = 'enabled';
|
2016-05-03 14:23:31 +00:00
|
|
|
|
2016-06-07 06:46:45 +00:00
|
|
|
var outputFile = path.join(__dirname, '../../docs/translations.json');
|
2016-05-03 14:23:31 +00:00
|
|
|
|
|
|
|
var translations = [];
|
|
|
|
|
|
|
|
|
2016-06-07 06:46:45 +00:00
|
|
|
this.onBrowserLog = function(browser, log, type) {
|
2016-05-03 14:23:31 +00:00
|
|
|
|
2018-02-27 09:08:31 +00:00
|
|
|
if (log === undefined || typeof log !== 'string') {
|
2016-05-03 14:23:31 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-02-27 09:08:31 +00:00
|
|
|
if (log.substring(0, 1) === '\'') {
|
|
|
|
log = log.substring(1, log.length - 1);
|
2016-05-03 14:23:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
var obj = JSON.parse(log);
|
|
|
|
|
|
|
|
if (obj.type === 'translations') {
|
|
|
|
translations.push(obj.msg);
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
return;
|
|
|
|
}
|
2016-06-07 06:46:45 +00:00
|
|
|
};
|
2016-05-03 14:23:31 +00:00
|
|
|
|
|
|
|
|
2016-06-07 06:46:45 +00:00
|
|
|
this.onRunComplete = function() {
|
2018-03-14 20:43:53 +00:00
|
|
|
translations = uniqueBy(function(e) {return e;}, translations);
|
|
|
|
translations = sortBy(translations, function(e) {return e;});
|
2016-05-03 14:23:31 +00:00
|
|
|
|
|
|
|
fs.writeFileSync(outputFile, JSON.stringify(translations, null, 2));
|
|
|
|
};
|
2016-06-07 06:46:45 +00:00
|
|
|
}
|
2016-05-03 14:23:31 +00:00
|
|
|
|
|
|
|
module.exports = {
|
2016-06-07 06:46:45 +00:00
|
|
|
'reporter:translation-reporter' : [ 'type', TranslationReporter ]
|
2016-05-03 14:23:31 +00:00
|
|
|
};
|