nextcloud /
passman-webextension
| 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) { |
||
|
0 ignored issues
–
show
|
|||
| 28 | if (!translate_key.hasOwnProperty('placeholders') && en[translate_key].hasOwnProperty('placeholders')) { |
||
| 29 | console.log('Fixed ' + file + ' translate key: ' + translate_key); |
||
|
0 ignored issues
–
show
|
|||
| 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
|
|||
| 37 | } |
||
| 38 | }); |
||
| 39 | |||
| 40 | } |
When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically: