Created
March 5, 2020 14:09
-
-
Save sazzer/d54603aa94fb70b349d35a6471e2a441 to your computer and use it in GitHub Desktop.
Catch missing message keys in tests using i18next
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 LanguageDetector from "i18next-browser-languagedetector"; | |
import defaultTranslations from "./messages.json"; | |
import i18n from "i18next"; | |
import { initReactI18next } from "react-i18next"; | |
i18n | |
.use(LanguageDetector) | |
.use(initReactI18next) | |
.init({ | |
resources: { | |
dev: { | |
translation: defaultTranslations | |
} | |
}, | |
nsSeparator: false, | |
debug: false, | |
interpolation: { | |
escapeValue: false | |
}, | |
parseMissingKeyHandler: key => { | |
if (process.env.NODE_ENV === "test") { | |
throw new Error(`Missing message key: ${key}`); | |
} else { | |
return `!!${key}!!`; | |
} | |
} | |
}); | |
export default i18n; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment