translation-file-validator
v2.0.1
Published
Script to check for missing keys in translation files
Maintainers
Readme
translation-checker
Check missing keys across translation objects.
Installation
pnpm add -D translation-file-validator
or npm i --save-dev translation-file-validator
Usage
const es = {
hola: "mundo",
nested: {
existing: "both",
missing: "falta",
},
};
const en = {
goodbye: "world",
nested: {
existing: "both",
deepNest: {
missingToo: "missing",
},
},
};const {
TranslationChecker,
TranslationFile,
} = require("translation-file-validator");
const languages = [
new TranslationFile("Spanish", es),
new TranslationFile("English", en),
];
const checker = new TranslationChecker(languages);
checker.check();API
type ComparatorResult = {
locale: string;
missingKeys: string[];
};
checker.check(options?: { log?: boolean }): ComparatorResult[];const result = checker.check({ log: false });log defaults to true. Arrays are treated as leaf keys.
ESM
import {
TranslationChecker,
TranslationFile,
} from "translation-file-validator";
const languages = [
new TranslationFile("Spanish", es),
new TranslationFile("English", en),
];
const checker = new TranslationChecker(languages);
checker.check();Console output
┌──────────┬────────────────────────────┐
│ Language │ Missing translations │
├──────────┼────────────────────────────┤
│ Spanish │ goodbye │
│ │ nested.deepNest.missingToo │
├──────────┼────────────────────────────┤
│ English │ hola │
│ │ nested.missing │
└──────────┴────────────────────────────┘Development
pnpm testpnpm typecheckpnpm build
