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
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
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?
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.
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.