From bef5bfa22ae42aeeb47f70967569fd39b2700893 Mon Sep 17 00:00:00 2001 From: David Ralph Date: Wed, 15 Mar 2023 20:55:54 +0000 Subject: [PATCH] fix(dev): script didn't work --- scripts/updatetranslations.js | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/scripts/updatetranslations.js b/scripts/updatetranslations.js index abd1883a..081adc25 100644 --- a/scripts/updatetranslations.js +++ b/scripts/updatetranslations.js @@ -2,24 +2,30 @@ const fs = require('fs'); const merge = require('@eartharoid/deep-merge'); +const compareAndRemoveKeys = (json1, json2) => { + for (let key in json1) { + if (json2.hasOwnProperty(key)) { + if (typeof json1[key] === 'object' && typeof json2[key] === 'object') { + compareAndRemoveKeys(json1[key], json2[key]); + } + } else { + delete json1[key]; + } + } +} + fs.readdirSync('../src/translations').forEach((file) => { if (file === 'en_GB.json') { return; } - const newdata = merge( - require('../src/translations/en_GB.json'), - require('../src/translations/' + file), - ); - - // remove unused strings const en = require('../src/translations/en_GB.json'); - const keys = Object.keys(newdata); - const enkeys = Object.keys(en); - const unused = keys.filter((key) => !enkeys.includes(key)); - unused.forEach((key) => { - delete newdata[key]; - }); + const newdata = merge(en, require('../src/translations/' + file)); + + // remove strings not in english file + compareAndRemoveKeys(newdata, en); + + // write new file fs.writeFileSync('../src/translations/' + file, JSON.stringify(newdata, null, 2)); // add new line