lemmy/ui/translation_report.ts

63 lines
1.8 KiB
TypeScript
Raw Normal View History

import { en } from './src/translations/en';
2019-08-26 17:42:53 -04:00
import { eo } from './src/translations/eo';
import { es } from './src/translations/es';
import { de } from './src/translations/de';
import { fa } from './src/translations/fa';
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 14:20:21 -04:00
import { nl } from './src/translations/nl';
import { it } from './src/translations/it';
2020-01-26 12:37:07 -05:00
import { fi } from './src/translations/fi';
2020-01-26 15:20:25 -05:00
import { ca } from './src/translations/ca';
2020-02-05 13:12:13 -05:00
import { pt_BR } from './src/translations/pt_br';
import fs from 'fs';
2020-01-26 14:31:34 -05:00
const files = [
{ t: ca, n: 'ca' },
2020-01-26 14:31:34 -05:00
{ t: de, n: 'de' },
{ t: fa, n: 'fa' },
2020-01-26 14:31:34 -05:00
{ t: eo, n: 'eo' },
{ t: es, n: 'es' },
{ t: fi, n: 'fi' },
{ t: fr, n: 'fr' },
{ t: it, n: 'it' },
{ t: nl, n: 'nl' },
2020-02-05 13:12:13 -05:00
{ t: pt_BR, n: 'pt-br' },
2020-01-26 14:31:34 -05:00
{ t: ru, n: 'ru' },
{ t: sv, n: 'sv' },
{ t: zh, n: 'zh' },
];
const masterKeys = Object.keys(en.translation);
2020-01-26 13:53:57 -05:00
const readmePath = '../README.md';
2020-01-26 13:53:57 -05:00
const open = '<!-- translations -->';
const close = '<!-- translationsstop -->';
2020-01-26 13:53:57 -05:00
const readmeTxt = fs.readFileSync(readmePath, { encoding: 'utf8' });
2020-01-26 13:53:57 -05:00
const before = readmeTxt.split(open)[0];
const after = readmeTxt.split(close)[1];
2020-01-26 15:49:47 -05:00
function difference(a: Array<string>, b: Array<string>): Array<string> {
return a.filter(x => !b.includes(x));
}
2020-01-26 14:31:34 -05:00
const report =
2020-01-26 14:31:34 -05: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 13:53:57 -05:00
const alteredReadmeTxt = `${before}${open}\n\n${report}\n${close}${after}`;
fs.writeFileSync(readmePath, alteredReadmeTxt);