You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

34 lines
1.1 KiB

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