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.

build-locales-coverage.js 923B

1234567891011121314151617181920212223242526272829303132
  1. const { readdirSync, writeFileSync } = require("fs");
  2. const files = readdirSync(`${__dirname}/../src/locales`);
  3. const flatten = (object) =>
  4. Object.keys(object).reduce(
  5. (initial, current) => ({ ...initial, ...object[current] }),
  6. {},
  7. );
  8. const locales = files.filter(
  9. (file) => file !== "README.md" && file !== "percentages.json",
  10. );
  11. const percentages = {};
  12. for (let index = 0; index < locales.length; index++) {
  13. const currentLocale = locales[index];
  14. const data = flatten(require(`${__dirname}/../src/locales/${currentLocale}`));
  15. const allKeys = Object.keys(data);
  16. const translatedKeys = allKeys.filter((item) => data[item] !== "");
  17. const percentage = (100 * translatedKeys.length) / allKeys.length;
  18. percentages[currentLocale.replace(".json", "")] = parseInt(percentage);
  19. }
  20. writeFileSync(
  21. `${__dirname}/../src/locales/percentages.json`,
  22. JSON.stringify(percentages, null, 2),
  23. "utf8",
  24. );