/**
 * i18n configuration
 *
 * Two locales: English (default) and French.
 * Language is detected from wahrbWizardConfig.locale.
 * Moment locale is synced for react-dates calendar day headers.
 */
import i18n from 'i18next';
import { initReactI18next } from 'react-i18next';
import moment from 'moment';
import 'moment/locale/fr';
import fr from './locales/fr.json';
import en from './locales/en.json';

const config = window.wahrbWizardConfig || {};
const locale = (config.locale || 'en').split(/[-_]/)[0];

// Sync moment locale so react-dates shows correct day abbreviations (Lu, Ma, Me... vs Mo, Tu, We...)
moment.locale(locale);

i18n.use(initReactI18next).init({
  resources: { fr: { translation: fr }, en: { translation: en } },
  lng: locale,
  fallbackLng: 'en',
  interpolation: { escapeValue: false },
});

export default i18n;
