Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non-static support #4

Closed
5 tasks done
justincy opened this issue Aug 17, 2020 · 5 comments · Fixed by #5
Closed
5 tasks done

Non-static support #4

justincy opened this issue Aug 17, 2020 · 5 comments · Fixed by #5

Comments

@justincy
Copy link
Owner

justincy commented Aug 17, 2020

Due to #3 and the fact that we plan on using next-i18next (which doesn't support static pages anyway), we're going to give up on supporting static pages for now and focus on just getting SSR working with getInitialProps().

We'll get rid of the dynamic [locale] directory and just detect the lang in middleware, setting the value on the req object, and somehow use that value to instantiate i18n.

TODO:

  • Remove [locale] dynamic dir
  • Lookup locale and set on req query
  • Use locale from query to instantiate i18n
  • Render in other langs
  • Fix language detection on the server
@justincy
Copy link
Owner Author

Domain routing with next-i18next: i18next/next-i18next#16 (comment)

@justincy
Copy link
Owner Author

Based on the link above, I was able to get this working. But it's not ideal yet. It looks like it's always rendering in English on the server and then detecting the correct lang on the browser and updating the language.

Maybe there's a bug in the language detection in the server.

@justincy
Copy link
Owner Author

The header I was relying on for the hostname was express specific. I fixed it to work without express.

@justincy justincy mentioned this issue Aug 17, 2020
@bitsmyth
Copy link

bitsmyth commented Sep 18, 2020

Hey I came across your repo and just wanted to provide some input for you.

By adding getInitialProps() to the _app file you will disable automatic static generation. For my understanding, your entire project will run SSR, which is not ideal if you have static sites, in matter of fact you will be paying for something what otherwise would come free.

A better aproach would be to detect the language in _app.jsx just on the clientside with useEffect() so you can have the automatic static feature enabled and open a modal with the different language options if the detected language is different from the displayed one. From that point the user can decide what he wants to view.

Disclaimer
I dont know if this is possible with next-i18next as I am currently searching for a solution I described above.

@justincy
Copy link
Owner Author

That could work if you're okay with not having any text shown until the language is detected and the translation strings are loaded. I also don't know whether it could be done with next-i18next. Let me know what you find out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants