import i18n from 'i18next';
import { initReactI18next } from 'react-i18next';
import hu from './hu.json';
import en from './en.json';
import de from './de.json';
import es from './es.json';
import fr from './fr.json';

const locale = window.varihuConfig?.locale || 'en_US';
const lang = locale.split('_')[0]; // 'hu_HU' → 'hu', 'de_DE' → 'de'

i18n.use(initReactI18next).init({
  resources: {
    hu: { translation: hu },
    en: { translation: en },
    de: { translation: de },
    es: { translation: es },
    fr: { translation: fr },
  },
  lng: lang,
  fallbackLng: 'en',
  interpolation: {
    escapeValue: false, // React already escapes
  },
  keySeparator: '.', // Enable nested keys (settings.title)
  nsSeparator: false, // Disable namespace separator
});

export default i18n;
