import i18n, { Resource, TFunction } from 'i18next';
import { initReactI18next } from 'react-i18next';

export default function initI18n(
  resources: Resource,
  language = 'el'
): Promise<TFunction> {
  return i18n
    .use(initReactI18next) // passes i18n down to react-i18next
    .init({
      resources: resources,
      lng: language,
      keySeparator: '.', // we use keys in form messages.welcome
      interpolation: {
        escapeValue: false, // react already safes from xss
      },
    });
}
