-
-
Notifications
You must be signed in to change notification settings - Fork 762
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
next export
does not work
#10
Comments
Interesting issue. I protected a couple of the language logic areas with simple That said, this project isn't really friendly to I'm curious as to how you expected this to work? Perhaps I'm missing something? The only workable "solution" I can think of is to have the server render nothing, and the client can successfully fetch translated content as needed. This would depend upon NextJs exposing some sort of env var to indicate that an |
Hey @isaachinman, Thanks for your prompt reply and for the great work on all things i18next. My maybe naïve expectation was, that the export would write translated strings to static html. The resulting app/site would then have a set of pages for the defaultLanguage and another set of pages for every additional language inside a lang-folder (e.g. I'm pretty sure there once was a react-i18next example for nextjs that exported like that. But thinking about it a little more, i see that language switching might prove a bit tricky in that scenario in terms of keeping the route and not linking to I will search for that example and see if it really exports as described above. Thanks again and best regards! Till |
Ah, I see. That would indeed be very cool. I see two main problems with that: 1. Too opinionatedThis approach would really only work with the 2. Requires build-step changesThis would also require serious build-time changes, as we'd need to essentially run All of that said, if you can find that example I would be very interested to see the approach. Regardless of all of this, I think I can get Let me know what you think. |
@tizzle I added my initial thoughts on a branch called support-next-export. The aforementioned graceful degradation of SSR seems to be working fine. However, I realised that of course the In short, it's sort of a lose-lose. I need to think awhile on this. Regardless of how we proceed, it will definitely be important to include this information in the README. My initial feeling is that we should just not support |
the react-i18next sample had a working export but that did not generate files per language - just the client did fetch the missing translations from /static/ and rendered (no server - no SSR) edit: And yes - no subpaths at that time |
Hi @isaachinman, i think nextjs leaves the custom path definitions for exports to the user. There is a thing called You can see this in action here: https://github.com/zeit/next.js/blob/canary/examples/with-static-export/next.config.js For next-i18next this would be the place where the localeSubpaths had to be added. As i see it, this would definitely mean some manual work on the users' side and thus making the super minimal setup of this package more complex. I also think the aforementioned static export example that worked as i expected made heavy use of this. Maybe this helps to provide some export capabilities. I will also think about this a bit more. |
@jamuhl Then, that is exactly what is achieved on the support-next-export branch. I suppose we can merge this if users really want it, but it seems like it misses the entire point to me. Also, if you want to have a static translated website with NextJs, you might as well just create all the routes manually with the content directly inside the React components, and do a |
@isaachinman yes...misses the point - at that point (😄) in react-i18next sample i wasn't in the mood anylonger to argue about it making sense -> just let them do the export and have that clientside react app ;) |
Hey @isaachinman and @jamuhl, i totally agree with you that the benefits of a static export are very small. Maybe a prominent statement in the README would be enough to make this clear. Feel free to close. Thanks for your discussion. |
This is fixed with #15. Now, doing No future plans to support any kind of custom export process with locale subdirs. |
If someone full export: |
@isaachinman Is this (particularly |
@balazsorban44 Yes, I believe |
I will try by myself, but if you have a good idea of how this could be achieved, I would be happy to look at your take! 🙂 |
Will be nice to see any example of this! |
@isaachinman I have a different problem here. But I think it's related. |
My workaround for SSG (
export async function getStaticPaths() {
return {
paths: i18n.locales.map(locale => ({ params: { locale } })),
fallback: false,
}
}
export async function getStaticProps({ params }) {
const locale = params?.locale || i18n.defaultLocale
return {
props: {
...await serverSideTranslations(locale, ['common']),
},
}
}
import { useRouter } from 'next/router'
import { i18n } from '../next-i18next.config'
const HomeFallback = () => {
const router = useRouter()
// Make sure we're in the browser
if (typeof window !== 'undefined')
// @TODO: Use locale on localStorage / browser preference
router.replace(`${i18n.defaultLocale}/${router.pathname}`)
return null
}
export default HomeFallback Checkout my sample repo: michchan/next-i18next-ssg-workaround@0caac9e |
Describe the bug
When doing a
next export
to built a static page, i get the following error:To Reproduce
Steps to reproduce the behavior:
cd example
yarn
yarn add next-i18next
yarn run dev
-> Worksyarn run next build
-> Worksyarn run next export
-> FailsExpected behaviour
A static version of the app/page should be built.
OS (please complete the following information):
The text was updated successfully, but these errors were encountered: