2

我有一个基于 next 和 react 的项目,使用 i18next 包我遇到以下警告,我认为这是根据反应分析器加载 i18n 需要大量时间的原因:

您尚未在页面级组件上声明 namespacesRequired 数组:withI18nextTranslation(Error)。这将导致所有命名空间都被发送到客户端,可能会对您的应用程序的性能产生负面影响。有关更多信息,请参阅: https ://github.com/isaachinman/next-i18next#4-declaring-namespace-dependencies

注释:翻译工作正常,我已经在我的所有组件中声明了 namespacesRequierd,除了 404。

这是我的 i18n 配置:

const NextI18Next = require('next-i18next').default
const { localeSubpaths } = require('next/config').default().publicRuntimeConfig
const path = require('path');

module.exports = new NextI18Next({
    preload: ['fa'],
    defaultLanguage: 'fa',
    otherLanguages: ['en','ar'],
    localeSubpaths,
    localePath: path.resolve('./public/static/locales'),
    localeStructure: '{{lng}}/{{ns}}',
    fallbackLng: 'fa',
    ignoreRoutes:['/_next/', '/static/', '/public/', '/api/'],
    serverLanguageDetection: false,
    defaultNS: 'common',
    localeExtension: 'json'
});

next.config.js :

const { nextI18NextRewrites } = require('next-i18next/rewrites');

rewrites: async () => nextI18NextRewrites(localeSubpaths),
           publicRuntimeConfig: {
               localeSubpaths
          }

版本:
package.json:

"i18next": "^19.7.0"

纱线:

    next-i18next@^6.0.2:
  version "6.0.2"
  dependencies:
    "@types/express" "^4.16.1"
    core-js "^3"
    hoist-non-react-statics "^3.2.0"
    i18next "^19.6.3"
    i18next-browser-languagedetector "^5.0.0"
    i18next-fs-backend "^1.0.7"
    i18next-http-backend "^1.0.17"
    i18next-http-middleware "^3.0.2"
    path-match "^1.2.4"
    prop-types "^15.6.2"
    react-i18next "^11.7.0"
    url "^0.11.0"

我的 server.js 文件中没有与此相关的内容。

4

0 回答 0