1
0
mirror of https://github.com/adobe/brackets.git synced 2024-11-20 01:42:55 +01:00

Add grunt task to check for correct nls keys

This commit is contained in:
Marcel Gerber 2015-06-22 19:38:10 +02:00
parent ac23edb990
commit 2fbb44a447
2 changed files with 50 additions and 1 deletions

View File

@ -320,7 +320,7 @@ module.exports = function (grunt) {
grunt.registerTask('install', ['write-config', 'less']);
// task: test
grunt.registerTask('test', ['jshint', 'jasmine']);
grunt.registerTask('test', ['jshint', 'jasmine', 'nls-check']);
// grunt.registerTask('test', ['jshint', 'jasmine', 'jasmine_node']);
// task: set-release

View File

@ -246,6 +246,55 @@ module.exports = function (grunt) {
request.end();
});
grunt.registerTask("nls-check", "Checks if all the keys in nls files are defined in root", function () {
var done = this.async(),
PATH = "src/nls",
ROOT_LANG = "root",
rootDefinitions = {},
definitions,
unknownKeys,
encounteredErrors;
function getDefinitions(abspath) {
var fileContent,
definitions = [];
fileContent = grunt.file.read(abspath);
fileContent.split("\n").forEach(function (line) {
var match = line.match(/^\s*"(\S+)"\s*:/);
if (match && match[1]) {
definitions.push(match[1]);
}
});
return definitions;
}
// Extracts all nls keys from nls/root
grunt.file.recurse(PATH + "/" + ROOT_LANG, function (abspath, rootdir, subdir, filename) {
rootDefinitions[filename] = getDefinitions(abspath);
});
// Compares nls keys in translations with root ones
grunt.file.recurse(PATH, function (abspath, rootdir, subdir, filename) {
if (!subdir || subdir === ROOT_LANG) {
return;
}
definitions = getDefinitions(abspath);
unknownKeys = [];
unknownKeys = definitions.filter(function (key) {
return rootDefinitions[filename].indexOf(key) < 0;
});
if (unknownKeys.length) {
grunt.log.writeln("There are unknown keys included in " + PATH + "/" + subdir + "/" + filename + ":", unknownKeys);
encounteredErrors = true;
}
});
done(encounteredErrors);
});
build.getGitInfo = getGitInfo;
return build;