reactjs - 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 文件所做的更改
解决方案
推荐阅读
- javascript - 如何检查 Javascript 中是否已经存在变体组合?
- python - Tensorflow_docs 未显示在环境的安装窗口中
- mongodb - Mogodb 不会安装在我的 Mac 上。我安装了自制软件以安装 Mongodb,但我收到了一些错误消息
- php - 在我的 WooCommerce 相关产品小部件中排除特定类别
- swift - SwiftUI 视图和结构中没有有用解释的错误
- azure - 在 Kusto 的动态值中替换/删除给定键的值
- python - 使用带有对称系数矩阵的 scipy.linalg.solve (assume_a='sym')
- javascript - Leetcode 关于为什么我的代码不起作用的两个和问题
- swift - UICollectionView CompositionalLayout 不调用 UIScrollDelegate
- machine-learning - 尽管多次尝试特征选择,但用于电影评论的朴素贝叶斯分类器的准确性非常低