import i18next from "i18next";
import React, { useEffect } from "react";
import { I18nextProvider, Translation } from "react-i18next";
const RicosTranslate = ({
  children,
  locale,
  localeResource
}) => {
  const [forceCounter, forceUpdate] = React.useState(0);
  const i18nInstance = React.useMemo(() => {
    const instance = i18next.createInstance({
      lng: locale,
      keySeparator: "$",
      interpolation: { escapeValue: false },
      react: { useSuspense: true },
      resources: { [locale]: { translation: localeResource } }
    });
    instance.init();
    return instance;
  }, []);
  useEffect(() => {
    i18nInstance.addResourceBundle(locale, "translation", localeResource);
    i18nInstance.changeLanguage(locale, (err) => {
      if (!err) {
        forceUpdate(forceCounter + 1);
      }
    });
  }, [locale, localeResource]);
  return /* @__PURE__ */ React.createElement(I18nextProvider, { i18n: i18nInstance }, /* @__PURE__ */ React.createElement(Translation, { i18n: i18nInstance }, (t) => {
    return children(t);
  }));
};
export {
  RicosTranslate
};
//# sourceMappingURL=ricos-translate.js.map
