import i18n from "i18next";
import languageDetector from "i18next-browser-languagedetector";
import { initReactI18next } from "react-i18next";
import { BaseTexts } from "./localization/BaseTexts";
import { CommentsTexts } from "./localization/CommentsTexts";
import { CommonTexts } from "./localization/CommonTexts";
import { ConsentTexts } from "./localization/ConsentTexts";
import { HeaderAppTexts } from "./localization/HeaderAppTexts";
import { HeaderTexts } from "./localization/HeaderTexts";
import { HelpTexts } from "./localization/HelpTexts";
import { HistoryTexts } from "./localization/HistoryTexts";
import { ParametersTexts } from "./localization/ParametersTexts";
import { SentenceTexts } from "./localization/SentenceTexts";
import { TreeTexts } from "./localization/TreeTexts";
import { UploadTexts } from "./localization/UploadTexts";
function buildResources(namespaces) {
    return {
        en: Object.fromEntries(Object.entries(namespaces).map(([key, texts]) => [key, texts.en])),
        "pt-BR": Object.fromEntries(Object.entries(namespaces).map(([key, texts]) => [key, texts["pt-BR"]])),
        it: Object.fromEntries(Object.entries(namespaces).map(([key, texts]) => [key, texts.it])),
    };
}
const CORE_NAMESPACES = {
    base: BaseTexts,
    common: CommonTexts,
    header: HeaderTexts,
    "header-app": HeaderAppTexts,
    upload: UploadTexts,
    help: HelpTexts,
    consent: ConsentTexts,
};
const FEATURE_NAMESPACES = {
    comments: CommentsTexts,
    tree: TreeTexts,
    sentence: SentenceTexts,
    parameters: ParametersTexts,
    history: HistoryTexts,
};
export const commonResources = buildResources(CORE_NAMESPACES);
export const featureResources = buildResources(FEATURE_NAMESPACES);
export function mergeResources(core = commonResources, features = featureResources) {
    const locales = ["en", "pt-BR", "it"];
    return Object.fromEntries(locales.map((locale) => [
        locale,
        {
            ...core[locale],
            ...features[locale],
        },
    ]));
}
export function commonLocalization(includeFeatures = true) {
    i18n
        .use(initReactI18next)
        .use(languageDetector)
        .init({
        resources: includeFeatures ? mergeResources() : commonResources,
        fallbackLng: "en",
        defaultNS: "common",
        interpolation: {
            escapeValue: false,
        },
    });
}
