Issues (71)

fixLocale.js (2 issues)

javascript_analysis.suspicious_code.debug_code

Debugging Code Minor
1
var fs = require('fs');
2
var en = JSON.parse(fs.readFileSync('_locales/en/messages.json', 'utf8'));
3
4
var walkSync = function (dir, filelist) {
5
    var files = fs.readdirSync(dir);
6
    filelist = filelist || [];
7
    files.forEach(function (file) {
8
        if (fs.statSync(dir + file).isDirectory()) {
9
            filelist = walkSync(dir + file + '/', filelist);
10
        }
11
        else {
12
            filelist.push(dir + file);
13
        }
14
    });
15
    return filelist;
16
};
17
18
var language_files = [];
19
language_files = walkSync('_locales/', language_files);
20
21
for (var i = 0; i < language_files.length; i++) {
22
    var file = language_files[i];
23
    if(file == '_locales/en/messages.json'){
24
        continue;
25
    }
26
    var json_data = JSON.parse(fs.readFileSync(file, 'utf8'));
27
    for (var translate_key in json_data) {
28
        if (en[translate_key] && !translate_key.hasOwnProperty('placeholders') && en[translate_key].hasOwnProperty('placeholders')) {
29
            console.log('Fixed ' + file + ' translate key: ' + translate_key);
0 ignored issues
show
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
30
            json_data[translate_key].placeholders = en[translate_key].placeholders;
31
        }
32
    }
33
    var options = { flag : 'w' };
34
    fs.writeFile(file, JSON.stringify(json_data, null, 4), function (err) {
35
        if(err){
36
           console.log('Error during saving');
0 ignored issues
show
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
37
        }
38
    });
39
40
}