使用NextJS上的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发布于 2022-07-05 23:51:39
参数名称是区域设置,而不是地区。您正在传递当前的地区,而不是所有的地区。我的代码片段
index.tsx
import { getStaticPropsTranslations } from '@/utils/i18n'
export async function getServerSideProps({ locale }: { locale: string }) {
return {
props: {
...(await getStaticPropsTranslations(locale)),
},
}
}@/utils/i18n.ts
import { serverSideTranslations } from 'next-i18next/serverSideTranslations'
export const getStaticPropsTranslations = async (locale: string) => {
return {
...(await serverSideTranslations(locale, ['instructions',])),
}
}https://stackoverflow.com/questions/72875937
复制相似问题