summaryrefslogtreecommitdiffstats
path: root/ui/translation_report.ts
blob: fae0359f1f9811def1ea7cb451dc9aec238ca273 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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;
}