You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
930 B
32 lines
930 B
const { readdirSync, writeFileSync } = require("fs"); |
|
const files = readdirSync(`${__dirname}/../src/locales`); |
|
|
|
const flatten = (object) => |
|
Object.keys(object).reduce( |
|
(initial, current) => ({ ...initial, ...object[current] }), |
|
{}, |
|
); |
|
|
|
const locales = files.filter( |
|
(file) => file !== "README.md" && file !== "percentages.json", |
|
); |
|
|
|
const percentages = {}; |
|
|
|
for (let index = 0; index < locales.length; index++) { |
|
const currentLocale = locales[index]; |
|
const data = flatten(require(`${__dirname}/../src/locales/${currentLocale}`)); |
|
|
|
const allKeys = Object.keys(data); |
|
const translatedKeys = allKeys.filter((item) => data[item] !== ""); |
|
|
|
const percentage = (100 * translatedKeys.length) / allKeys.length; |
|
|
|
percentages[currentLocale.replace(".json", "")] = parseInt(percentage); |
|
} |
|
|
|
writeFileSync( |
|
`${__dirname}/../src/locales/percentages.json`, |
|
`${JSON.stringify(percentages, null, 2)}\n`, |
|
"utf8", |
|
);
|
|
|