import i18n from 'i18next';

import en from '../locales/en.json';
import ar from '../locales/ar.json';

const resources = {
  en: {
    translation: en,
  },
  ar: {
    translation: ar,
  },
};

let defaultLng = 'ar';
if (typeof window !== 'undefined') {
  defaultLng = localStorage.getItem('language') || 'ar';
}

i18n
  .init({
    resources,
    lng: defaultLng, // Initialize with saved language on client
    fallbackLng: 'en',
    interpolation: {
      escapeValue: false, // React already safe from xss
    },
  });

export default i18n;
