lemmy/ui/translation_report.ts

59 lines
1.7 KiB
TypeScript
Raw Normal View History

import { en } from './src/translations/en';
2019-08-26 21:42:53 +00:00
import { eo } from './src/translations/eo';
import { es } from './src/translations/es';
import { de } from './src/translations/de';
import { zh } from './src/translations/zh';
import { fr } from './src/translations/fr';
import { sv } from './src/translations/sv';
import { ru } from './src/translations/ru';
2019-08-29 18:20:21 +00:00
import { nl } from './src/translations/nl';
import { it } from './src/translations/it';
2020-01-26 17:37:07 +00:00
import { fi } from './src/translations/fi';
2020-01-26 20:20:25 +00:00
import { ca } from './src/translations/ca';
import fs from 'fs';
2020-01-26 19:31:34 +00:00
const files = [
{ t: ca, n: 'ca' },
2020-01-26 19:31:34 +00:00
{ t: de, n: 'de' },
{ t: eo, n: 'eo' },
{ t: es, n: 'es' },
{ t: fi, n: 'fi' },
{ t: fr, n: 'fr' },
{ t: it, n: 'it' },
{ t: nl, n: 'nl' },
{ t: ru, n: 'ru' },
{ t: sv, n: 'sv' },
{ t: zh, n: 'zh' },
];
const masterKeys = Object.keys(en.translation);
2020-01-26 18:53:57 +00:00
const readmePath = '../README.md';
2020-01-26 18:53:57 +00:00
const open = '<!-- translations -->';
const close = '<!-- translationsstop -->';
2020-01-26 18:53:57 +00:00
const readmeTxt = fs.readFileSync(readmePath, { encoding: 'utf8' });
2020-01-26 18:53:57 +00:00
const before = readmeTxt.split(open)[0];
const after = readmeTxt.split(close)[1];
2020-01-26 20:49:47 +00:00
function difference(a: Array<string>, b: Array<string>): Array<string> {
return a.filter(x => !b.includes(x));
}
2020-01-26 19:31:34 +00:00
const report =
2020-01-26 19:31:34 +00:00
'lang | done | missing\n' +
'---- | ---- | -------\n' +
files
.map(file => {
const keys = Object.keys(file.t.translation);
const pct: number = (keys.length / masterKeys.length) * 100;
const missing = difference(masterKeys, keys);
return `${file.n} | ${pct.toFixed(0)}% | ${missing}`;
})
.join('\n');
2020-01-26 18:53:57 +00:00
const alteredReadmeTxt = `${before}${open}\n\n${report}\n${close}${after}`;
fs.writeFileSync(readmePath, alteredReadmeTxt);