首页 > 解决方案 > Next-i18next 初始语言环境参数未传递到 serverSideTranslations

问题描述

它在本地工作。但是,一旦我将它部署在 firebase 上,它会产生 nextServer 500 内部错误。

next-i18下一个版本

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.jsi18nextnext-i18next

解决方案


我有同样的问题,然后我记得我必须在更改文件后手动重新启动 NEXTJS SERVER 。next.config.js

重启服务器帮了我。


推荐阅读