Skip to content

Commit

Permalink
chore(i18n): create config file
Browse files Browse the repository at this point in the history
  • Loading branch information
brdtheo committed Sep 24, 2023
1 parent d504a29 commit a7a7abd
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 7 deletions.
32 changes: 32 additions & 0 deletions src/i18n.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import i18n from "i18next";
import { initReactI18next } from "react-i18next";
import Backend from "i18next-http-backend";
import LanguageDetector from "i18next-browser-languagedetector";
import { EN, ES } from "./i18n/index.js";

// the translations
// (tip move them in a JSON file and import them,
// or even better, manage them separated from your code: https://react.i18next.com/guides/multiple-translation-files)
const resources = {
en: EN,
es: ES,
};

i18n
.use(Backend)
// detect user language
// learn more: https://github.com/i18next/i18next-browser-languageDetector
.use(LanguageDetector)
.use(initReactI18next) // passes i18n down to react-i18next
.init({
resources,
fallbackLng: "en", // language to use, more information here: https://www.i18next.com/overview/configuration-options#languages-namespaces-resources
// you can use the i18n.changeLanguage function to change the language manually: https://www.i18next.com/overview/api#changelanguage
// if you're using a language detector, do not define the lng option

interpolation: {
escapeValue: false, // react already safes from xss
},
});

export default i18n;
16 changes: 9 additions & 7 deletions src/main.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import ReactDOM from 'react-dom/client'
import App from './App.jsx'
import './index.css'
import { BrowserRouter } from 'react-router-dom'
import ReactDOM from "react-dom/client";
import App from "./App.jsx";
import "./index.css";
import { BrowserRouter } from "react-router-dom";

ReactDOM.createRoot(document.getElementById('root')).render(
import "./i18n.js";

ReactDOM.createRoot(document.getElementById("root")).render(
<BrowserRouter>
<App />
<App />
</BrowserRouter>
)
);

0 comments on commit a7a7abd

Please sign in to comment.