martinkr/next-export-i18n

Get the default languages in getStaticProps

NguyenChiTrung1310 opened this issue · 1 comments

How can I get the default languages in getStaticProps with next-export-i18n like this:

export const getStaticProps: GetStaticProps = async context => {
  console.log('context: ', context)
  if (locale === 'de') {
     return {
      notFound: true
    }
  }

  return {
    props: {}
  }
}

Currently the context return undefined. My problem is that when a page has a default lang is de then it should be redirect to 404 page
Please help me to help this issue. Thank you.

Hi @NguyenChiTrung1310,

I don't exactly understand your issue here. You set the default language by yourself, it's a fixed value. If you want it to be dynamic, you can read it from the configuration file. Anyway, getStaticProps is run only once on server side and at build time and the use case for the library is to provide i18n on exported pages on the client side.

I assume you are looking for the current language instead of the default language and redirect to 404 for pages that are not available in a specific language? In this case, I would suggest to check for the query parameter on the url and redirect accordingly in the body of your page.

Let me know if you have additional questions.

Cheers