| 59 | } |
| 60 | |
| 61 | async function testFile(file) { |
| 62 | let thisFile = {} |
| 63 | |
| 64 | try { |
| 65 | thisFile = JSON.parse(fs.readFileSync(path.join(testPath, `${file}.json`))) |
| 66 | const thisFileKeys = new Set(Object.keys(thisFile)) |
| 67 | const extraKeys = new Set([...thisFileKeys].filter((x) => !baseLocaleKeys.has(x))) |
| 68 | const missingKeys = new Set([...baseLocaleKeys].filter((x) => !thisFileKeys.has(x))) |
| 69 | |
| 70 | if ( extraKeys.size !== 0 ) { |
| 71 | test.warn(`${file} :: Extra keys removed : ${[...extraKeys].join(', ')}`) |
| 72 | for ( const thisKey of extraKeys ) { delete thisFile[thisKey] } |
| 73 | } |
| 74 | if ( missingKeys.size !== 0 ) { |
| 75 | test.warn(`${file} :: Missing keys added : ${[...missingKeys].join(', ')}`) |
| 76 | const stringsToTranslate = [...missingKeys].map((x) => baseLocaleData[x]) |
| 77 | |
| 78 | await translator.translateText( |
| 79 | stringsToTranslate, |
| 80 | 'en', |
| 81 | fileMap[file] |
| 82 | ).then((results) => { |
| 83 | for ( const [idx, thisKey] of [...missingKeys].entries() ) { |
| 84 | thisFile[thisKey] = results[idx].text |
| 85 | } |
| 86 | test.step(`${file} :: Got Translated Data`) |
| 87 | }).catch((err) => { |
| 88 | for ( const thisKey of missingKeys ) { |
| 89 | thisFile[thisKey] = baseLocaleData[thisKey] |
| 90 | } |
| 91 | test.error(`${file} :: Translation failed, added english : ${err}`) |
| 92 | }) |
| 93 | } |
| 94 | } catch (err) { |
| 95 | test.error(`Could not process ${file} :: ${err}`) |
| 96 | } |
| 97 | |
| 98 | return thisFile |
| 99 | } |
| 100 | |
| 101 | function fileWriter(data, file) { |
| 102 | test.step(`${file} :: Writing Clean File`) |