Skip to content

Instantly share code, notes, and snippets.

@anlisha-maharjan
Last active April 26, 2022 06:31
Show Gist options
  • Select an option

  • Save anlisha-maharjan/a87c0a8e72abd46d8aab0bc0f3fa7647 to your computer and use it in GitHub Desktop.

Select an option

Save anlisha-maharjan/a87c0a8e72abd46d8aab0bc0f3fa7647 to your computer and use it in GitHub Desktop.
Setup i18n.js configuration for languages "en" & "no".
import i18n from "i18next";
import { initReactI18next } from "react-i18next";
import HttpApi from "i18next-http-backend";
import LanguageDetector from "i18next-browser-languagedetector";
const fallbackLng = ["en"];
const availableLanguages = ["en", "no"];
i18n
.use(HttpApi) // load translations using http (default public/locals/en/translations)
.use(LanguageDetector) // detect user language
.use(initReactI18next) // pass the i18n instance to react-i18next.
.init({
fallbackLng, // fallback language is english.
preload: ["en", "no"],
detection: {
checkWhitelist: true, // options for language detection
},
supportedLngs: availableLanguages,
react: {
useSuspense: false,
},
debug: false,
whitelist: availableLanguages,
});
export default i18n;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment