如何解决Next-i18next 初始语言环境参数未传递到 serverSideTranslations
它在本地工作。 但是,一旦我将它部署到 firebase 上,它就会产生 nextServer 500 内部错误。
next-i18next 版本
8.1.3
配置
module.exports = {
i18n: {
defaultLocale: 'en',locales: ['en','ko'],},};
代码
_app.tsx
import { appWithTranslation } from 'next-i18next';
const App = ({ Component,pageProps }: AppProps): JSX.Element => {
return (
<Provider store={store}>
<MainWrapper>
<Component {...pageProps} />
</MainWrapper>
</Provider>
);
};
export default appWithTranslation(App);
关于 serverSideRendering 的代码片段
export const getStaticProps: any = async ({ locale }) => ({
props: {
...(await serverSideTranslations(locale,[])),});
export const getServerSideProps: GetServerSideProps = async (context) => {
const { teamId,email } = context.query;
let teamName;
if (!teamId) {
return { props: {} };
}
if (teamId) {
teamName = await getTeamName(teamId as string);
}
return {
props: {
teamId,teamName,email: email || '',...(await serverSideTranslations(context.locale,};
};
解决方法
几天前我遇到了同样的错误,就我而言,根本原因是我的 '.'
文件。我使用的是 next.config.js
并且无法使其与 i18n 的配置一起使用。
我之前是这样设置的:
next-compose-plugins
所以现在我要添加没有 // next.config.js
module.exports = withPlugins([
[
withImages({
esModule: true
})
],i18n // error
])
的配置:
withPlugins
不确定这是否适合您,但出于调试目的,我建议您仅使用 // next.config.js
module.exports = withImages({
esModule: true,i18n
})
配置测试您的应用程序。
i18n
我的 // next.config.js
module.exports = {
i18n
}
示例:
next-i18next.config.js
,
使用 next-compose-plugins 时,从他们的 Usage section,
// next.config.js
const withPlugins = require('next-compose-plugins');
module.exports = withPlugins([...plugins],nextConfiguration);
nextConfiguration 应该是配置,意思是一个对象。
所以下面的代码片段应该可以工作:
module.exports = withPlugins(
[withMdx(mdxConfig)],{
i18n,}
)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。