配置 i18next 以使用警告日志而不是默认信息级别

Configure i18next to use warning logs instead of default info level

目前我有很多 i18next 的日志,这使得控制台难以使用:

我需要 i18next 使用警告级别而不是默认信息级别,以便能够过滤它们。

我正在查看 docs,但我没有看到任何选项。我当前的配置是:

i18n
  .use(XHR)
  .use(LanguageDetector)
  .init({
    debug: true,
    lng: 'en',
    keySeparator: false,
    addMissing: true,
    interpolation: {
      escapeValue: false
    },

    resources: {
      en: {
        translations: translationEng
    },
    ns: ['translations'],
    defaultNS: 'translations'
  })

您可以禁用 debug: false,这将禁用默认的 console.log 内容。 以及 i18n 实例上的事件侦听器 missingKey

i18n
  .use(XHR)
  .use(LanguageDetector)
  .init({
    debug: false, // <-- disable default console.log
    lng: 'en',
    keySeparator: false,
    addMissing: true,
    interpolation: {
      escapeValue: false
    },

    resources: {
      en: {
        translations: translationEng
    },
    ns: ['translations'],
    defaultNS: 'translations'
  });

i18n.on('missingKey', (lng, namespace, key, fallbackValue) => {
   console.warn(lng, namespace, key, fallbackValue);
})

基于this code

其他选项是使用 options.missingKeyHandler 传递自定义处理程序来处理丢失的密钥。

i18n
  .use(XHR)
  .use(LanguageDetector)
  .init({
    debug: false, // disable this
    lng: 'en',
    keySeparator: false,
    addMissing: true,
    interpolation: {
      escapeValue: false
    },

    resources: {
      en: {
        translations: translationEng
    },
    ns: ['translations'],
    defaultNS: 'translations',
    saveMissing: true, // must be enabled
    missingKeyHandler: (lng, ns, key, fallbackValue) => {
       console.warn(lng, ns, key, fallbackValue)
    }
  })

基于this code