2019-08-30 20:14:53 +02:00
|
|
|
/* eslint-disable no-console */
|
|
|
|
|
2018-11-30 23:37:29 +02:00
|
|
|
const fs = require('fs');
|
|
|
|
const path = require('path');
|
2019-08-30 20:14:53 +02:00
|
|
|
const sh = require('shelljs');
|
2018-11-30 23:37:29 +02:00
|
|
|
|
|
|
|
const source = require('../lang/en.json');
|
|
|
|
const table = require('markdown-table');
|
|
|
|
const tableRegex = /(<!-- START langtable -->)(.|\n)*(<!-- END langtable -->)/;
|
|
|
|
|
2019-08-30 20:14:53 +02:00
|
|
|
let doc = fs.readFileSync(path.join(__dirname, '..', 'docs', 'translations-needed.md'), 'utf8');
|
|
|
|
const tableData = [['Language file', 'Missing translations']];
|
2018-11-30 23:37:29 +02:00
|
|
|
|
2019-08-30 20:14:53 +02:00
|
|
|
const filepaths = sh.find(path.join(__dirname, '..', 'lang', '**', '!(zh-Hans|zh-Hant)*.json'));
|
2018-11-30 23:37:29 +02:00
|
|
|
|
2019-08-30 20:14:53 +02:00
|
|
|
filepaths.forEach((filepath) => {
|
|
|
|
const filename = path.basename(filepath);
|
2018-11-30 23:37:29 +02:00
|
|
|
|
|
|
|
if (filename === 'en.json') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-30 20:14:53 +02:00
|
|
|
const target = require(filepath);
|
2023-02-21 18:03:47 +02:00
|
|
|
|
|
|
|
// Special case for English, the assumption being that since the keys are English only
|
|
|
|
// a few strings need to be altered for regional differences, e.g. en-GB.
|
|
|
|
if (filename.startsWith('en-')) {
|
|
|
|
console.log(`${filename} English - should be manually checked.`);
|
|
|
|
tableData.push([`${filename} (has ${Object.keys(target).length})`, 'Needs manual checking. Can safely use most default strings.']);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-30 20:14:53 +02:00
|
|
|
const missing = [];
|
|
|
|
|
2018-11-30 23:37:29 +02:00
|
|
|
for (const string in source) {
|
|
|
|
if (!target[string]) {
|
|
|
|
console.log(`${filename} missing "${string}"`);
|
|
|
|
missing.push(string);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (missing.length > 0) {
|
|
|
|
console.error(`${filename} is missing ${missing.length} translations.`);
|
|
|
|
tableData.push([`${filename} (missing ${missing.length})`, missing[0]]);
|
2019-08-30 20:14:53 +02:00
|
|
|
for (let i = 1; i < missing.length; i++) {
|
2018-11-30 23:37:29 +02:00
|
|
|
tableData.push(['', missing[i]]);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
console.log(`${filename} is up to date.`);
|
|
|
|
tableData.push([`${filename} (Complete)`, '']);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-08-30 20:14:53 +02:00
|
|
|
doc = doc.replace(tableRegex, '$1\n' + table(tableData) + '\n$3');
|
|
|
|
fs.writeFileSync(path.join(__dirname, '..', 'docs', 'translations-needed.md'), doc, 'utf8');
|