【问题标题】:How to load prefixed json files in i18next?如何在 i18next 中加载带前缀的 json 文件?
【发布时间】:2018-07-11 22:22:20
【问题描述】:

我的项目与 i18next 库配合良好。这是我的文件工作:

i18n/index.js

import i18n from 'i18next';
// import LanguageDetector from 'i18next-browser-languagedetector';
import pt from './locales/pt/common.json';
import en from './locales/en/common.json';

const options = {
  interpolation: { escapeValue: false },
  lng: 'en',

  resources: {
    pt: {
      common: pt,
    },
    en: {
      common: en,
    },
  },

  fallbackLng: 'pt',

  ns: ['common'],

  defaultNS: 'common',

  react: {
    wait: true,
  },
};

i18n.init(options);


export default i18n;

i18n/locales/en/common.json

"editor": {
  "sidebar": {
    "header": {
      ...
    }
  }
}

i18n/locales/pt/common.json

"editor": {
  "sidebar": {
    "header": {
      ...
    }
  }
}

但是,我需要在我的 json 文件前面加上 enpt-BR。这样,我的项目停止工作。有人有简单的解决方案吗?

i18n/locales/en/common.json

"en" {
  "editor": {
    "sidebar": {
      "header": {
        ...
      }
    }
  }
}

i18n/locales/pt/common.json

"pt-BR" {
  "editor": {
    "sidebar": {
      "header": {
        ...
      }
    }
  }
}

【问题讨论】:

    标签: i18next


    【解决方案1】:

    我在Gitbub 上发布了这个问题,@jamuhl 回答了。他的解决方案是:

    resources: {
      pt: {
        common: pt[pt-BR],
      },
      en: {
        common: en.en,
      },
    },
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-03-03
      • 2021-09-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-20
      • 1970-01-01
      相关资源
      最近更新 更多