我正在努力让我的网站正常运行。我的网站是一个 React + vite,使用 i18next.js 库来翻译文本。应用程序托管在 GitHub 页面上,我也使用我的自定义域名。问题是
Failed to load resource: the server responded with a status of 404 ()
表明我的路径一定是错误的。我尝试改变路径大约 10 次,已经尝试了不同的选项。例子:
loadPath: "{{lng}}.json",
loadPath: `${domain}/translations/{{lng}}.json`,
loadPath: "/translations/{{lng}}.json",
等等,但似乎没有任何作用。
我在开发版本中的翻译位于 /src/translations/(nameofMyfiles).json 下
这是我的 i18n.js 文件:
import i18n from "i18next";
import Backend from "i18next-http-backend";
import LanguageDetector from "i18next-browser-languagedetector";
import { initReactI18next } from "react-i18next";
i18n
.use(Backend)
.use(LanguageDetector)
.use(initReactI18next) // passes i18n down to react-i18next
.init({
lng: "pl",
backend: {
loadPath: "/translations/{{lng}}.json",
},
fallbackLng: "pl",
debug: false,
interpolation: {
escapeValue: false,
},
react: { wait: true },
});
export default i18n;