2016-05-03 14:23:31 +00:00
|
|
|
'use strict';
|
|
|
|
|
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
|
|
|
|
2016-05-03 14:23:31 +00:00
|
|
|
var unique = require('lodash/array/unique');
|
|
|
|
var sortBy = require('lodash/collection/sortBy');
|
|
|
|
|
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
|
|
|
|
|
|
|
if ( log === undefined || typeof log !== 'string' ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( log.substring( 0, 1 ) === '\'' ) {
|
|
|
|
log = log.substring( 1, log.length - 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
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() {
|
2016-05-03 14:23:31 +00:00
|
|
|
translations = unique(translations);
|
|
|
|
translations = sortBy(translations);
|
|
|
|
|
|
|
|
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
|
|
|
};
|