PHP 8.2.30
Preview: useSSR.js Size: 1.22 KB
/proc/thread-self/root/home/byroehnu/.trash/node_modules11/react-i18next/src/useSSR.js

import { useContext } from 'react';
import { getI18n, I18nContext } from './context.js';

export function useSSR(initialI18nStore, initialLanguage, props = {}) {
  const { i18n: i18nFromProps } = props;
  const { i18n: i18nFromContext } = useContext(I18nContext) || {};
  const i18n = i18nFromProps || i18nFromContext || getI18n();

  // opt out if is a cloned instance, eg. created by i18next-http-middleware on request
  // -> do not set initial stuff on server side
  if (i18n.options && i18n.options.isClone) return;

  // nextjs / SSR: getting data from next.js or other ssr stack
  if (initialI18nStore && !i18n.initializedStoreOnce) {
    i18n.services.resourceStore.data = initialI18nStore;

    // add namespaces to the config - so a languageChange call loads all namespaces needed
    i18n.options.ns = Object.values(initialI18nStore).reduce((mem, lngResources) => {
      Object.keys(lngResources).forEach((ns) => {
        if (mem.indexOf(ns) < 0) mem.push(ns);
      });
      return mem;
    }, i18n.options.ns);

    i18n.initializedStoreOnce = true;
    i18n.isInitialized = true;
  }

  if (initialLanguage && !i18n.initializedLanguageOnce) {
    i18n.changeLanguage(initialLanguage);
    i18n.initializedLanguageOnce = true;
  }
}

Directory Contents

Dirs: 0 × Files: 15

Name Size Perms Modified Actions
1.92 KB lrw-r--r-- 2026-02-28 00:27:18
Edit Download
655 B lrw-r--r-- 2026-02-28 00:27:42
Edit Download
358 B lrw-r--r-- 2026-02-28 00:28:02
Edit Download
138 B lrw-r--r-- 2026-02-28 00:28:14
Edit Download
892 B lrw-r--r-- 2026-02-28 00:28:28
Edit Download
237 B lrw-r--r-- 2026-02-28 00:28:30
Edit Download
1018 B lrw-r--r-- 2026-02-28 00:28:52
Edit Download
290 B lrw-r--r-- 2026-02-28 00:28:56
Edit Download
13.06 KB lrw-r--r-- 2026-02-28 00:28:58
Edit Download
663 B lrw-r--r-- 2026-02-28 00:29:00
Edit Download
1.22 KB lrw-r--r-- 2026-02-28 00:29:06
Edit Download
4.97 KB lrw-r--r-- 2026-02-28 00:29:08
Edit Download
4.10 KB lrw-r--r-- 2026-02-28 00:29:10
Edit Download
712 B lrw-r--r-- 2026-02-28 00:29:12
Edit Download
1.23 KB lrw-r--r-- 2026-02-28 00:29:14
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).