i18next undefined 不是一个对象(评估'_i18next.default.services.formatter.add')
i18next undefined is not an object (evaluating '_i18next.default.services.formatter.add')
为什么我收到此错误消息:
undefined is not an object (evaluating '_i18next.default.services.formatter.add')
代码:
import i18next from "i18next";
import { initReactI18next } from "react-i18next";
import LanguageDetector from 'i18next-browser-languagedetector';
import HttpApi from 'i18next-http-backend';
import { DateTime } from 'luxon';
i18next
.use(HttpApi)
.use(LanguageDetector)
.use(initReactI18next)
.init({
react: {
useSuspense: true
},
fallbackLng: 'en',
compatibilityJSON: 'v3',
lng: 'de',
debug: process.env.NODE_ENV === 'development',
backend: {
loadPath: `http://192.168.0.249:4000/public/locales/{{lng}}/translation.json`,
},
interpolation: {
escapeValue: false,
},
keySeparator: '.'
});
// new usage
i18next.services.formatter.add('DATE_HUGE', (value, lng, options) => {
return DateTime.fromJSDate(value).setLocale(lng).toLocaleString(DateTime.DATE_HUGE)
});
export default i18next;
谁能帮我解决这个问题?
我从那里得到它:
您可能没有使用 i18next >= 21.3.0
在那种情况下使用旧格式选项:https://www.i18next.com/translation-function/formatting#legacy-format-function-i18next-less-than-21.3.0
interpolation: {
escapeValue: false, // not needed for react as it escapes by default
format: (value, format, lng) => { // legacy usage
if (value instanceof Date) {
return DateTime.fromJSDate(value).setLocale(lng).toLocaleString(DateTime[format])
}
return value;
}
},
为什么我收到此错误消息:
undefined is not an object (evaluating '_i18next.default.services.formatter.add')
代码:
import i18next from "i18next";
import { initReactI18next } from "react-i18next";
import LanguageDetector from 'i18next-browser-languagedetector';
import HttpApi from 'i18next-http-backend';
import { DateTime } from 'luxon';
i18next
.use(HttpApi)
.use(LanguageDetector)
.use(initReactI18next)
.init({
react: {
useSuspense: true
},
fallbackLng: 'en',
compatibilityJSON: 'v3',
lng: 'de',
debug: process.env.NODE_ENV === 'development',
backend: {
loadPath: `http://192.168.0.249:4000/public/locales/{{lng}}/translation.json`,
},
interpolation: {
escapeValue: false,
},
keySeparator: '.'
});
// new usage
i18next.services.formatter.add('DATE_HUGE', (value, lng, options) => {
return DateTime.fromJSDate(value).setLocale(lng).toLocaleString(DateTime.DATE_HUGE)
});
export default i18next;
谁能帮我解决这个问题?
我从那里得到它:
您可能没有使用 i18next >= 21.3.0
在那种情况下使用旧格式选项:https://www.i18next.com/translation-function/formatting#legacy-format-function-i18next-less-than-21.3.0
interpolation: {
escapeValue: false, // not needed for react as it escapes by default
format: (value, format, lng) => { // legacy usage
if (value instanceof Date) {
return DateTime.fromJSDate(value).setLocale(lng).toLocaleString(DateTime[format])
}
return value;
}
},