import i18n from "i18next";
import LanguageDetector from "i18next-browser-languagedetector";
import { initReactI18next } from "react-i18next";

import enCollection from "../locales/en/collection.json";
import enCommon from "../locales/en/common.json";
import enOnboarding from "../locales/en/onboarding.json";
import enSettings from "../locales/en/settings.json";
import enSetups from "../locales/en/setups.json";
import enThreads from "../locales/en/threads.json";

import deCollection from "../locales/de/collection.json";
import deCommon from "../locales/de/common.json";
import deOnboarding from "../locales/de/onboarding.json";
import deSettings from "../locales/de/settings.json";
import deSetups from "../locales/de/setups.json";
import deThreads from "../locales/de/threads.json";

i18n
	.use(LanguageDetector)
	.use(initReactI18next)
	.init({
		resources: {
			en: {
				common: enCommon,
				collection: enCollection,
				threads: enThreads,
				setups: enSetups,
				onboarding: enOnboarding,
				settings: enSettings,
			},
			de: {
				common: deCommon,
				collection: deCollection,
				threads: deThreads,
				setups: deSetups,
				onboarding: deOnboarding,
				settings: deSettings,
			},
		},
		supportedLngs: ["en", "de"],
		fallbackLng: "en",
		defaultNS: "common",
		interpolation: {
			escapeValue: false,
		},
		detection: {
			order: ["localStorage", "navigator"],
			lookupLocalStorage: "gearbox-language",
			caches: ["localStorage"],
		},
	});

export default i18n;
