Dev Helpers
← Back

Calculate translation coverage by locale

Calculate translation coverage by locale. Inspect the transformed data in the console.

Open this example in the interactive library

Source code

const rows = [
  { key: "home", en: "Home", fr: "Accueil" },
  { key: "save", en: "Save", fr: "Enregistrer" },
  { key: "help", en: "Help", fr: "" },
];
const result = Object.fromEntries(
  ["en", "fr"].map((lang) => [
    lang,
    rows.filter((r) => (lang === "fr" ? r.fr : r.en)).length / rows.length,
  ]),
);
console.log(JSON.stringify(result, null, 2));

Sample output

{
  "en": 1,
  "fr": 0.6666666666666666
}