Skip to content

Instantly share code, notes, and snippets.

@hmelenok
Created January 11, 2022 10:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hmelenok/9b5b26d8e1378801700de4c1aad96899 to your computer and use it in GitHub Desktop.
Save hmelenok/9b5b26d8e1378801700de4c1aad96899 to your computer and use it in GitHub Desktop.
React example of app library initialization
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