Skip to content

Instantly share code, notes, and snippets.

@smoralb
Last active January 11, 2022 18:11
Show Gist options
  • Save smoralb/d3e31078f663ae7f00d738e3293c396f to your computer and use it in GitHub Desktop.
Save smoralb/d3e31078f663ae7f00d738e3293c396f to your computer and use it in GitHub Desktop.
Basic i18n set up
import i18n from "i18next";
import { initReactI18next } from "react-i18next"
import Backend from 'i18next-http-backend';
import LanguageDetector from 'i18next-browser-languagedetector';
const DETECTION_OPTIONS = {
order: ['navigator']
};
i18n
.use(Backend) // Automatically detects translation files
.use(initReactI18next)
.use(LanguageDetector) // Autommatically detects the browser's language
.init({
detection: DETECTION_OPTIONS, // Detection options
fallbackLng: "en", // If does not find the language of the browser, is going to use english as a default language
react: {
useSuspense: true
}
});
export default i18n;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment