将Next-I18Next与NextJ和Typescript配置
使用NextJS和TypeScript上的Next-I18Next库,我遇到了底部报告的问题。我该如何修复?我还上传了使用库的文件的代码,这没什么特别的。
_app.tsx
import { appWithTranslation } from "next-i18next"
const MyApp = ({ Component, pageProps }: AppProps) => {
return <Component {...pageProps} />
}
export default appWithTranslation(MyApp);
index.tsx
export const getStaticProps = async ({ locales }:{locales: string}) => {
return {
props: { ...(await serverSideTranslations(locales, ['common'])) }
};
};
next-i18next.config.js
module.exports = {
i18n: {
defaultLocale: 'en',
locales: ['en', 'it']
},
}
next.config.js
const { i18n } = require('./next-i18next.config');
module.exports = {
i18n
}
错误:
Error: Initial locale argument was not passed into serverSideTranslations
enter code here
Using the next-i18next library on NextJS and Typescript I encountered the problem reported at the bottom. How can I fix it? I also uploaded the code of the files where I use the library, nothing special.
_app.tsx
import { appWithTranslation } from "next-i18next"
const MyApp = ({ Component, pageProps }: AppProps) => {
return <Component {...pageProps} />
}
export default appWithTranslation(MyApp);
index.tsx
export const getStaticProps = async ({ locales }:{locales: string}) => {
return {
props: { ...(await serverSideTranslations(locales, ['common'])) }
};
};
next-i18next.config.js
module.exports = {
i18n: {
defaultLocale: 'en',
locales: ['en', 'it']
},
}
next.config.js
const { i18n } = require('./next-i18next.config');
module.exports = {
i18n
}
ERROR:
Error: Initial locale argument was not passed into serverSideTranslations
enter code here
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
参数名称是语言环境而不是地方
。您正在通过当前的语言环境并非所有地区。我的代码段
index.tsx
@/utils/i18n.ts
Parameter name is locale not locales
. You're passing current locale not all locales. My code snippet
index.tsx
@/utils/i18n.ts