Created
January 11, 2022 10:43
-
-
Save hmelenok/9b5b26d8e1378801700de4c1aad96899 to your computer and use it in GitHub Desktop.
React example of app library initialization
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 i18NextLib from 'i18next'; | |
import {initReactI18next} from 'react-i18next'; //To have a react context | |
import {resources} from 'dictionary-package/lib/bundles/app-1'; //reduce bundles if there is many | |
import {defaultInterpolation} from 'dictionary-package/lib/lib/helpers'; // day-to-day functions to format text | |
const i18next = i18NextLib.createInstance(); | |
i18next.use(initReactI18next).init({ | |
lng: 'en', | |
resources, | |
fallbackLng: 'en', | |
saveMissing: true, | |
interpolation: defaultInterpolation,//Learn more at i18n docs | |
parseMissingKeyHandler: (key: string) => { | |
const message = `MISSING TRANSLATION for key: "${key}"`; | |
//Can be logger with alert if you forgot something | |
console.warn(message); | |
//Placeholder for missing key | |
return `⛔️`; | |
}, | |
}); | |
export {i18next}; | |
export default i18next; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment