@lingui/cli
Version:
Lingui CLI to extract messages, compile catalogs, and manage translation workflows
43 lines (42 loc) • 1.43 kB
JavaScript
import Table from "cli-table3";
import { styleText } from "node:util";
export function getStats(catalog) {
return [
Object.keys(catalog).length,
Object.keys(catalog).filter((key) => !catalog[key].translation).length,
];
}
export function printStats(config, catalogs) {
const table = new Table({
head: ["Language", "Total count", "Missing"],
colAligns: ["left", "center", "center"],
style: {
head: ["green"],
border: [],
compact: true,
},
});
Object.keys(catalogs)
.sort((a, b) => {
if (a === config.sourceLocale && b !== config.sourceLocale)
return -1;
if (b === config.sourceLocale && a !== config.sourceLocale)
return 1;
return a.localeCompare(b);
})
.forEach((locale) => {
if (locale === config.pseudoLocale)
return; // skip pseudo locale
const catalog = catalogs[locale];
// catalog is null if no catalog exists on disk and the locale
// was not extracted due to a `--locale` filter
const [all, translated] = catalog ? getStats(catalog) : ["-", "-"];
if (config.sourceLocale === locale) {
table.push({ [`${styleText("bold", locale)} (source)`]: [all, "-"] });
}
else {
table.push({ [locale]: [all, translated] });
}
});
return table;
}