lemmy/ui/translation_report.ts
2020-01-26 19:53:57 +01:00

58 lines
1.7 KiB
TypeScript
Vendored

import { en } from './src/translations/en';
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';
import { nl } from './src/translations/nl';
import { it } from './src/translations/it';
import { fi } from './src/translations/fi';
import fs from 'fs';
const readmePath = '../README.md';
const open = '<!-- translations -->';
const close = '<!-- translationsstop -->';
const readmeTxt = fs.readFileSync(readmePath, { encoding: 'utf8' });
const before = readmeTxt.split(open)[0];
const after = readmeTxt.split(close)[1];
const report = buildReport();
const alteredReadmeTxt = `${before}${open}\n\n${report}\n${close}${after}`;
fs.writeFileSync(readmePath, alteredReadmeTxt);
const difference = (a: Array<string>, b: Array<string>): Array<string> => a.filter(x => !b.includes(x));
function buildReport(): string {
const files = [
{ 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);
const report = '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");
return report;
}