【问题标题】:github pages not loading file from server in deployed React Appgithub页面没有从部署的React App中的服务器加载文件
【发布时间】:2020-12-22 19:13:12
【问题描述】:

我已经在 github 上部署了一个 react 项目,并在使用 github pages 进行查看时。我正在使用 i18next 为我的网络应用程序提供不同的翻译。当我通过 localhost 运行我的应用程序时,locales 文件夹被访问并正确翻译了我的应用程序的内容。但是,当使用 github 页面部署时,出现错误:

警告:

i18next::backendConnector: loading namespace translation for language en failed failed loading /locales/en/translation.json

错误:

request.js:60 GET https://user.github.io/locales/en/translation.json 404

所以我无法在我的语言环境文件夹中访问我的翻译。

我的文件夹结构(我的文件夹里面有更多的语言,而不是同级别的英语):public > locales > en > translation.json

来自以下文档的 i18next.js:

src > i18n.js 

带代码:

import i18n from 'i18next'; 
import { initReactI18next } from 'react-i18next';

import Backend from 'i18next-http-backend';
import LanguageDetector from 'i18next-browser-languagedetector';
// don't want to use this?
// have a look at the Quick start guide 
// for passing in lng and translations on init

const Languages = ['en' , 'gr']; //the languages I want 


i18n
  // load translation using http -> see /public/locales (i.e. https://github.com/i18next/react-i18next/tree/master/example/react/public/locales)
  // learn more: https://github.com/i18next/i18next-http-backend
  .use(Backend)
  // detect user language
  // learn more: https://github.com/i18next/i18next-browser-languageDetector
  .use(LanguageDetector)
  // pass the i18n instance to react-i18next.
  .use(initReactI18next)
  // init i18next
  // for all options read: https://www.i18next.com/overview/configuration-options
  .init({
    fallbackLng: 'en',
    debug: true,
    whitelist:Languages,

    interpolation: {
      escapeValue: false, // not needed for react as it escapes by default
    }


  });


export default i18n;

感谢您的帮助

【问题讨论】:

    标签: reactjs i18next


    【解决方案1】:

    要在 gh-pages 上部署,您需要调整托管 json 的 loadPath check this

    希望这项工作!

    【讨论】:

      猜你喜欢
      • 2018-02-28
      • 2020-09-12
      • 1970-01-01
      • 2019-04-08
      • 2022-10-05
      • 1970-01-01
      • 2022-11-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多