当locize名称空间使用x-cache抛出空的json响应时,阻止locize调用到达浏览器:标头中来自云前端的错误

问题描述

我正在使用i18next-chained-backend来认使用多个后端来使用本地翻译,并在存在名称间的情况下使用Locize翻译覆盖。

因此,我的本地翻译文件被加载,然后Locize调用获取特定的名称空间,即使该特定名称空间不存在于Locize上,Locize也会给出200个带有x缓存的响应代码:来自云前端的错误而不是未找到响应的404

我要实现的目标是,如果命名空间不存在,则停止此Locize调用。 我尝试将failLoadingOnEmptyJSON:true添加到后端,但这也无济于事。

请告诉我是否有一种方法可以通过响应中的x-cache标头或failLoadingOnEmptyJSON来停止该Locize调用,或者也可以通过任何其他方式来赞赏。 Locize调用具有动态名称空间,当Locize中存在该名称空间时,我会使用它覆盖本地翻译,如果Locize中不存在名称空间,则尝试停止该调用。 如果您认为这不可能,也请告诉我。 谢谢。

这是我的代码,我正在使用以下导入

i18next from 'i18next';
 Backend from 'i18next-chained-backend'; 
 Locize from 'i18next-Locize-backend';
 HttpApi from 'i18next-http-backend';

i18next
    .use(Backend)
    .init({
      fallbackLng:
    {
      'default': ['en-US']
    },load: 'currentOnly',ns: ['translations',`domain-${window.location.hostname}`],defaultNS: `domain-${window.location.hostname}`,fallbackNS: [`domain-${window.location.hostname}`,'translations'],order: ['localStorage','querystring','navigator'],lookupQuerystring: 'lng',allowMultiLoading: true,backend: {
        backends: [
          HttpApi,Locize
        ],backendOptions: [
          {
            loadpath: config.webPaths.assets + 'locales/{{lng}}/{{ns}}.json' // xhr load path for my own fallback
          },{
            failLoadingOnEmptyJSON: true,projectId: '',referenceLng: 'en-US',}
        ]
      },debug: true,detection: {
        caches: []
      },keySeparator: false,// we use content as keys

      interpolation: {
        formatSeparator: ','
      },react: {
        wait: true
      }
    },(err,t) => {
      if (err) return console.log('Something went wrong while loading.',err);
    }) ```

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)