Next-i18next: Use namespacesRequired inside getStaticProps?

Created on 18 Jul 2020  路  9Comments  路  Source: isaachinman/next-i18next

Describe the bug

I just updated my portfolio with the latest update of next.js. I would like to use getInitialProps (for i18n) with getStaticProps (to fetch blog articles).

I've just followed the tutorial on the readme.

On next build, I have You can not use getInitialProps with getStaticProps. To use SSG, please remove your getInitialProps

Steps to reproduce

export async function getStaticProps() {
  const res = await fetch('...')
  const posts = await res.json()
  return {
    props: {
      posts,
      unstable_revalidate: 10
    }
  }
}

Blog.getInitialProps = async () => ({
  namespacesRequired: ['heading']
})

export default Blog

Expected behaviour

Be able to use both methods, or else use the namespacesRequired key in getStaticProps.

How can I translate my page correctly while keeping my articles fetched? Is there an alternative?

Most helpful comment

@mirshko It's the next (big) thing on the roadmap for this package, but I haven't begun any serious work on it yet. It's going to require a pretty opinionated approach, wherein users _must_ use locale subpaths, and storaging user lang in a cookie won't be supported.

All 9 comments

This package does not support SSG as of yet, due to locale subpath and cookie support.

When will this be supported? It seems it works a bit through SSG just all the namespaces will come down.

@mirshko It's the next (big) thing on the roadmap for this package, but I haven't begun any serious work on it yet. It's going to require a pretty opinionated approach, wherein users _must_ use locale subpaths, and storaging user lang in a cookie won't be supported.

I think that's a happy medium! I don't think there's too much need for storing the preference in a cookie for sites that would use subpaths. deff a good trade off to keep blazing fast sites with i18n

@mirshko It's the next (big) thing on the roadmap for this package, but I haven't begun any serious work on it yet. It's going to require a pretty opinionated approach, wherein users _must_ use locale subpaths, and storaging user lang in a cookie won't be supported.

Sorry, I don't quite understand why "locale subpaths" are required to pass namespacesRequired via getStaticProps.
We don't and will never use "locale subpaths" since we found a manual way which works better with our SSG setup (closely following next.js guides and issues from this package)

If this is not crucial for SSG, an update to the warning might be helpful.

Thank you for your support.

Did I understand correctly that "getStaticProps" can't be used ? I wouldn't want to choose between localization and performance

The getStaticProps method is compatible with how next-i18next works, but we still have a runtime requirement of detecting language based on headers/cookies/etc, and performing relevant redirects.

Hi Isaac, Any idea how to solve this // or any workaround? Thanks.

The Vercel team plans to add i18n support to Next core, with first class support. From that point forward, SSG should be very simple.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

patsa picture patsa  路  6Comments

ddereszewski picture ddereszewski  路  3Comments

MichaelIT picture MichaelIT  路  4Comments

slava-lu picture slava-lu  路  6Comments

Jonesus picture Jonesus  路  6Comments