Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

il y a 3 ans
12345678910111213141516171819202122232425
  1. import { useContext } from 'react';
  2. import { getI18n, getHasUsedI18nextProvider, I18nContext } from './context';
  3. export function useSSR(initialI18nStore, initialLanguage) {
  4. var props = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  5. var i18nFromProps = props.i18n;
  6. var ReactI18nContext = useContext(I18nContext);
  7. var _ref = getHasUsedI18nextProvider() ? ReactI18nContext || {} : {},
  8. i18nFromContext = _ref.i18n;
  9. var i18n = i18nFromProps || i18nFromContext || getI18n(); // opt out if is a cloned instance, eg. created by i18next-express-middleware on request
  10. // -> do not set initial stuff on server side
  11. if (i18n.options && i18n.options.isClone) return; // nextjs / SSR: getting data from next.js or other ssr stack
  12. if (initialI18nStore && !i18n.initializedStoreOnce) {
  13. i18n.services.resourceStore.data = initialI18nStore;
  14. i18n.initializedStoreOnce = true;
  15. }
  16. if (initialLanguage && !i18n.initializedLanguageOnce) {
  17. i18n.changeLanguage(initialLanguage);
  18. i18n.initializedLanguageOnce = true;
  19. }
  20. }