feat: first shoot on translation

This commit is contained in:
Julien Froidefond
2025-02-27 11:31:39 +01:00
parent 3c46afb294
commit f39e4779cf
15 changed files with 635 additions and 143 deletions

42
src/i18n/i18n.ts Normal file
View File

@@ -0,0 +1,42 @@
"use client";
import i18n from "i18next";
import { initReactI18next } from "react-i18next";
import LanguageDetector from "i18next-browser-languagedetector";
// Importation des traductions
import frCommon from "./messages/fr/common.json";
import enCommon from "./messages/en/common.json";
// Ne pas initialiser i18next plus d'une fois
if (!i18n.isInitialized) {
i18n
.use(LanguageDetector) // Détecte la langue du navigateur
.use(initReactI18next)
.init({
resources: {
fr: {
common: frCommon,
},
en: {
common: enCommon,
},
},
defaultNS: "common",
fallbackLng: "fr",
interpolation: {
escapeValue: false, // React gère déjà l'échappement
},
detection: {
order: ["cookie", "localStorage", "navigator"],
lookupCookie: "NEXT_LOCALE",
caches: ["cookie"],
cookieOptions: {
path: "/",
maxAge: 365 * 24 * 60 * 60, // 1 an
},
},
});
}
export default i18n;