0

我正在使用 react-i18next 和 i18next-http-backend 来国际化我的项目

有人可以告诉我为什么 backendConnector/backend 有这么多实例吗?

请检查这张图片

我有这样的错误

TypeError: Converting circular structure to JSON
    --> starting at object with constructor 'Object'
    |     property 'backendConnector' -> object with constructor 'Connector'
    |     property 'backend' -> object with constructor 'Backend'
    --- property 'services' closes the circle
    at JSON.stringify (<anonymous>)
    at Object.parseData (<anonymous>:8:575)
    at <anonymous>:10:2639
    at i (<anonymous>:10:2659)
    at <anonymous>:10:2946
    at _ (<anonymous>:10:3072)
    at <anonymous>:10:3316
    at <anonymous>:201:34
    at Array.map (<anonymous>)
    at Object.emit (<anonymous>:201:24)
    at attachRenderer (react_devtools_backend.js:14086)
    at react_devtools_backend.js:14098
    at Map.forEach (<anonymous>)
    at initBackend (react_devtools_backend.js:14097)
    at setup (react_devtools_backend.js:10618)
    at welcome (react_devtools_backend.js:10564)

我只是想知道你能不能帮我解决这个问题

我的 i18n 代码是这个

import i18next from 'i18next';
import { initReactI18next } from 'react-i18next';
import LanguageDetector from 'i18next-browser-languagedetector';
import Backend from 'i18next-http-backend';

import { getStorage } from 'utils/storage';

const Detector = new LanguageDetector();

export const i18n = () => {
  const locale = 'ko';
  i18next
    // pass the i18n instance to react-i18next.
    .use(initReactI18next)
    // load resources from the backend api
    .use(Backend)
    // detect user language
    // learn more: https://github.com/i18next/i18next-browser-languageDetector
    .use(Detector)
    // init i18next
    // for all options read: https://www.i18next.com/overview/configuration-options
    .init({
      backend: {
        loadPath: '/locales/{{lng}}/{{ns}}.json',
        addPath: '/locales/{{lng}}/{{ns}}.json',
      },
      fallbackLng: locale,
      ns: ['common'],
      defaultNS: 'common',
      debug:
        process.env.NODE_ENV !== 'production' &&
        process.env.NODE_ENV !== 'test',

      interpolation: {
        escapeValue: false, // not needed for react as it escapes by default
      },
      supportedLngs: ['en', 'ko'],
      load: 'languageOnly',
      parseMissingKeyHandler: key => {
        return `__${key}`;
      },
    });

  return i18next;
};

4

0 回答 0