首页 > 解决方案 > ReactI18 在运行时检测 json 翻译的变化

问题描述

我正在将 reacti18 集成到我的 nextjs 应用程序中,到目前为止它工作得很好。语言环境保存在公用文件夹中,因此我希望如果我在运行时对任何 json 文件进行更改,则应立即在应用程序中检测到更改并呈现,但目前未检测到任何更改。

这是我的 i18n 文件

import i18n from 'i18next';
import LanguageDetector from 'i18next-browser-languagedetector';
import Backend from 'i18next-http-backend';
import { initReactI18next } from 'react-i18next';

void 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',
    interpolation: {
      escapeValue: false, // not needed for react as it escapes by default
    },
    react: {
      useSuspense: false, //   <---- this will do the magic
    },
  });

export default i18n;

语言检测器负责在运行时检测文件,但它不会检测应用程序运行时对任何 json 文件所做的更改

标签: reactjsnext.jsreact-i18next

解决方案


推荐阅读