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

import { createContext } from 'react';
import { getDefaults, setDefaults } from './defaults.js';
import { getI18n, setI18n } from './i18nInstance.js';
import { initReactI18next } from './initReactI18next.js';

export { getDefaults, setDefaults, getI18n, setI18n, initReactI18next };

export const I18nContext = createContext();

export class ReportNamespaces {
  constructor() {
    this.usedNamespaces = {};
  }

  addUsedNamespaces(namespaces) {
    namespaces.forEach((ns) => {
      if (!this.usedNamespaces[ns]) this.usedNamespaces[ns] = true;
    });
  }

  getUsedNamespaces() {
    return Object.keys(this.usedNamespaces);
  }
}

export function composeInitialProps(ForComponent) {
  return (ctx) =>
    new Promise((resolve) => {
      const i18nInitialProps = getInitialProps();

      if (ForComponent.getInitialProps) {
        ForComponent.getInitialProps(ctx).then((componentsInitialProps) => {
          resolve({
            ...componentsInitialProps,
            ...i18nInitialProps,
          });
        });
      } else {
        resolve(i18nInitialProps);
      }
    });
  // Avoid async for now - so we do not need to pull in regenerator

  // return async ctx => {
  //   const componentsInitialProps = ForComponent.getInitialProps
  //     ? await ForComponent.getInitialProps(ctx)
  //     : {};

  //   const i18nInitialProps = getInitialProps();

  //   return {
  //     ...componentsInitialProps,
  //     ...i18nInitialProps,
  //   };
  // };
}

export function getInitialProps() {
  const i18n = getI18n();
  const namespaces = i18n.reportNamespaces ? i18n.reportNamespaces.getUsedNamespaces() : [];

  const ret = {};
  const initialI18nStore = {};
  i18n.languages.forEach((l) => {
    initialI18nStore[l] = {};
    namespaces.forEach((ns) => {
      initialI18nStore[l][ns] = i18n.getResourceBundle(l, ns) || {};
    });
  });

  ret.initialI18nStore = initialI18nStore;
  ret.initialLanguage = i18n.language;

  return ret;
}

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).