-
-
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.js 10 #869
Comments
Yep, have been waiting for it to land. We'll want to rewrite so that the main concern of Would be very happy to have input from collaborators! |
@isaachinman nice! Could you elaborate a bit on what you mean by data management in this context? |
So, the NextJs core as of v10 intends to take all responsibility for locale routing. That means we can remove a lot of functionality from What NextJs v10 does not do, is handle any sort of actual data management for users. In the case of full SSG apps, you can, in theory, get away with passing your localisation data as props per page, kind of like this example. However, that means you'll be sending all of your translation data down to every single page. If i18n routing is being taken care of by NextJs internally, all that's left for a package like |
Very exciting release specifically in regards to internationalization. I am looking forward to be able to use SSG or at least Few things are still not clear to me:
Basically:
|
Does NextJS handle localization files? If it is using |
NextJs only handles the routing. Handling localisation files, splitting translations across pages, etc, will be the new goal of packages like I hope to spend some hours this weekend taking a deep look at a rewrite for |
This comment has been minimized.
This comment has been minimized.
@isaachinman Lmk if I can help. I've done some things to load translations specified with namespaces, with SSG. https://github.com/MathiasKandelborg/TRUE-framework/tree/master/util/i18n I have time to contribute so I might take a look myself. Would love to contribute, so let me know if there's anything I can begin with. |
@MathiasKandelborg I am starting to look into this now, but unfortunately only have about an hour today. OverviewI will write my thoughts below, to give any potential contributors a chance to work on this without my schedule blocking development. I understand that this is time-sensitive in a way, and would greatly appreciate help anyone might be able to offer. In general, the future version of It should be said that NextJs's i18n routing implementation has less features than As I wrote above, the main purpose of Software ApproachThe User's custom
|
Why a HOC? Wouldn't it better to use hooks instead? |
@SalahAdDin What about react legacy apps? If it goes only for hooks, they lose support because they have no functional approach as such |
Apps with React 16.8.0+ support hooks, which means that any project using React 16.0.0+ (Sep 2017) can upgrade without any breaking changes. React 16.8.0 is a minimum requirement for |
@kachkaev Okay then it would make sense |
@kachkaev but still many have not migrated class components to functional components. next-i18next currently supports If you mean the |
@jansepke but useTranslation does not work, i have tried and it doesn't, so you are required to receive the TFunction. Its weird because i18 should have the loaded translations but if you try to useTranslation, the translations are empty (Right now with my hooks app i'm forced to use the T everywhere with HoC because next-i18next does not inject correctly) |
@jansepke hooks are not for component wrapping. But it is still just a function. You could use any function to be a factory. However we would not use hooks in the react sense anymore. Thus we use @underfisk I use |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
We'll be using a HOC, let's keep discussion in this issue on topic. |
This comment has been minimized.
This comment has been minimized.
What about throwing a promise in one of the HOCs and thus leveraging the Suspense mechanism? 🤔 |
@kachkaev That's an experimental feature, and not really relevant what we want to do. The moments where we will need to await the init promise are either during SSG or SSR. A fully initialised i18next instance is serialised and sent down to the client per req, so there is no need to await in a client side setting. |
This looks promising! 🎉 Let's get some things going! 🥳 The project's new scope is "simply" integrating i18next with Next.js, right? Would it be fine for a first PR to try and cut as much as possible, get all the way down to the bone, and then get started with Next.js v10 and i18next? I think a project or a milestone (on this Github repo) with some issues etc. would help organize things a bit better. It might just be me liking to organize things a bit too much, though. There are several approaches to be made in regards to configuration and file loading. I'll spend some time today looking at different ways to approach the integration. I found an approach - i.e., the files I've linked to before - to include the translated files on build/compile time for SSG pages using a Next.js lifecycle (haven't tested others, but the concept should be the same). BTW, sorry for the late response! I've had a hectic week so far; I'm going to spend at least a few hours a day trying to solve this. I can't really progress my own project as I want to unless I use a library like this, so it's getting personal now! 😁 |
Hey @MathiasKandelborg.
Not sure that's necessary – if you want to focus on something, let's begin with the core functionality. I have the context necessary to quickly clean up the repo once the core work is done.
Can you explain what you mean? Loading translation files is something that Also, I will have at least a few hours to look into this tomorrow (8 Nov), so let me know if you make any progress in the meantime. |
Pretty crucial problem: Attempting to override, or compose upon Would be grateful for any suggestions. |
What if export const getServerSideProps = async () => { // or getStaticProps
return {
props: {
translationLookup: loadI18nextTranslations(["myPage", "whatever"]), // never executed on the client
},
};
};
const MyPage = ({ translationLookup }) => {
return (
<NextI18nextProvider translationLookup={translationLookup}>
pageContents
</NextI18nextProvider>
);
};
export default MyPage; The problem with this though is that if every page has |
An alternative solution would involve an API endpoint and Suspence inside some sort of In addition, each use of a not-yet-loaded namespace via |
Hey guys, I was trying to follow the example for my NextJS app, but was facing a problem when setting up a dynamic page like below - |
@nowshadfriday I think you just have to access the |
Maybe related to this? #919 |
I can't define interpolation.format option in 8.0.0-beta.4. |
Can you give a simple example? @isaachinman |
Btw @isaachinman I don't know if this has been addressed in this thread but I think not. How should apps handle common translations that are needed in _app (like for layouts)? Should the pages be responsible for requesting the namespace that the _app needs? |
@filipesmedeiros Namespaces get passed into the second argument of |
But we would have to explicitly pass 'common' on every page, correct (or make an app-land high order function to do it for us)? |
Yes. That's not something I would be looking to optimise for, at least not for the initial release. |
Update:
I will most likely release I imagine there might be some rough edges, but in general, migration of existing projects should be pretty straightforward. Here's the new setup: First, create a
|
Hey @isaachinman thanks a lot for this! Would you like a PR to do so? |
@LeonardDrs Yes, that would be great, thanks! |
Okay, doing it right now.
module.exports = {
i18n: {
locales: availableLanguages,
defaultLocale: "fr-FR",
localePath: path.resolve("some/path/to/locales"),
localeStructure: "{{lng}}",
nsSeparator: ":::",
keySeparator: "::",
postProcess: "sprintf",
use: [sprintf],
ns: "common",
},
};
const { i18n } = require('./next-i18next.config')
module.exports = {
i18n, // This includes also next-i18next custom parameters
} In this case, should we use this instead ? const { i18n } = require('./next-i18next.config')
module.exports = {
i18n: {
defaultLocale: i18n.defaultLocale,
locales: i18n.locales,
},
} I feel like it's worth mentioning somewhere |
@LeonardDrs No that's incorrect, and definitely a miscommunication on my part. Your setup would look like:
module.exports = {
i18n: {
locales: availableLanguages,
defaultLocale: "fr-FR",
},
localePath: path.resolve("some/path/to/locales"),
localeStructure: "{{lng}}",
nsSeparator: ":::",
keySeparator: "::",
postProcess: "sprintf",
use: [sprintf],
ns: "common",
}; As in, the Moreover, I'm fairly sure NextJs will throw if you pass unknown config options into it. |
Worth mentioning, you no longer need |
@janhesters Great point, and sorry for catching you on that. Open request: would anyone be willing to write a migration guide, once we've finalised the API? I think it would be more helpful if this came from an actual user, with an actual project. |
Hi all, I believe If anyone has a free moment, would you mind reviewing the new README? I am expecting to receive a number of issues immediately following release, and that's fine with a major version like this, but I would like to at least get the documentation correct from the start. |
Thank you for your time @isaachinman! Very excited for the 8.0.0 release. Heads up: We didn't get to it yet, but we'll migrate one of our biggest clients to from version 7 to built-in Next.js locale routing + version 8 in the upcoming two weeks. I'll take the time to closely review the new documentation and provide issues and pull requests for any things we'll find out along the way. Thank you and all of the other contributors very much for the plugin and taking the time to support Next.js version 10! |
I find the README good.
If we still want to preserve this part, we should edit the |
Good catch @LeonardDrs – I think that was a result of the merge from |
I have published Thanks everyone! |
I'm still not able to get it work with |
Is your feature request related to a problem? Please describe.
Next.js is just out, and introduces i18n routing primitives
https://nextjs.org/docs/advanced-features/i18n-routing
Describe the solution you'd like
I think a lot of the features of
next-i18next
can be dropped, sonext-i18next
really just focuses on thei18next
integration.Describe alternatives you've considered
n/a
Additional context
n/a
The text was updated successfully, but these errors were encountered: