Created
May 17, 2017 20:04
-
-
Save oharsta/a3c3452070c163d7911abbff023a9d73 to your computer and use it in GitHub Desktop.
Verifying every I18n translation is present in all translations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import I18n from "i18n-js"; | |
import en from "../locale/en"; | |
import nl from "../locale/nl"; | |
expect.extend({ | |
toContainKey(translation, key) { | |
const pass = (translation[key] !== undefined); | |
return { | |
message: () => `Expected ${key} to be present in ${JSON.stringify(translation)}`, | |
pass: pass | |
}; | |
}, | |
}); | |
test("All translations exists in EN and NL", () => { | |
const contains = (translation, translationToVerify) => { | |
Object.keys(translation).forEach(key => { | |
expect(translationToVerify).toContainKey(key); | |
const value = translation[key]; | |
if (typeof value === "object") { | |
contains(value, translationToVerify[key]) | |
} | |
}); | |
}; | |
contains(I18n.translations.en, I18n.translations.nl); | |
contains(I18n.translations.nl, I18n.translations.en); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment