versel不从getServerSideProps nextjs方法返回i18nexus键值

g0czyy6m  于 2023-01-25  发布在  其他
关注(0)|答案(1)|浏览(151)

我遇到了这个问题:我用next-i18 next加了一个翻译到我的站点上,为了开发的更快,我用了i18 nexus,开发应用的时候没有问题,但是上传到Versel的时候,i18 nexus的值根本不显示(仅输出键的名称)。对于输出,我使用getServerSideProps方法,我不能使用getStaticProps方法,因为在[id]组件中使用它需要getStaticPath,在项目中不需要它,因为我不通过SSR获取数据。
下一个-i18下一个.配置-失败

module.exports = {
   i18n: {
      locales: ['en', 'ru', 'ar', 'es'],
      defaultLocale: 'en'
   }
}

next.config

/** @type {import('next').NextConfig} */
const nextConfig = {
  reactStrictMode: false,
  swcMinify: true,
  images: {
    domains: ["cdn.worldota.net"]
  },
  i18n: {
    locales: ['en', 'ru', 'ar', 'es'],
    defaultLocale: 'en',
  },
  env: {
    API_HOST: 'http://localhost:3000/api'
  },
}

module.exports = nextConfig

_应用程序.tsx

function App({ Component, pageProps }: AppProps) {
//code

  return (
    <>
      <ReactReduxContext.Consumer>
        {({ store }) => (
          <PersistGate persistor={(store as any).__persistor} loading={<LoadingRouter />}>
            <Head>
              <link rel="icon" href={'./favicon.svg'} type="image/svg" />
            </Head>
            <div className='wrapper'>
              {loading && <LoadingRouter />}
              <Component {...pageProps} />
            </div>
          </PersistGate>
        )}
      </ReactReduxContext.Consumer>
    </>
  )
}

App.getInitialProps = wrapper.getInitialAppProps(store => async ({ ctx, Component }) => {
// store.dispatch(getUserData(userData.data.user)) и т.д.
   return {
    pageProps: Component.getInitialProps ? await Component.getInitialProps({ ...ctx, store 
   }) : {},
  }
})

index.tsx

const Home: NextPage<HomeType> = ({ locale }) => {
  const dispatch = useAppDispatch()

  useEffect(() => {
    dispatch(languageFunction(locale))
  }, [])

  return (
    <div className='shelters_housing'>
      <MainScreen />
      <div className='shelters_housing_flex'>
        <div className='shelters_housing_flex_container'>
          <TravelToEarn />
          <SearchByPlacementType />
          <PopularPlacesInRussia />
          <SubscribeNewsletter />
          <PopularHouses />
          <OurFavoriteDestinations />
        </div>
      </div>
      <SaveTimeAndMoney />
      <Footer />
    </div>
  )
}

export const getServerSideProps: GetStaticProps = async ({ locale }) => {
  return {
    props: {
      ...(await serverSideTranslations(locale!, ['main', 'footer', 'header', 'common', 'regions', 'discover'])),
      locale
    }
  }
}
3pmvbmvn

3pmvbmvn1#

听起来你需要在next-i18 next的文档中检查一下这个:
https://github.com/i18next/next-i18next#vercel-and-netlify
您需要在next-i18next.config.js中包含localePath: path.resolve('./public/locales')

相关问题