import React, { createContext, useContext, useMemo } from 'react';
import { getTranslator } from './translations';

const LanguageContext = createContext(() => (key) => key);

export function LanguageProvider({ language, children }) {
  const t = useMemo(() => getTranslator(language), [language]);

  return (
    <LanguageContext.Provider value={t}>
      {children}
    </LanguageContext.Provider>
  );
}

export function useTranslation() {
  return useContext(LanguageContext);
}
