-
-
Notifications
You must be signed in to change notification settings - Fork 764
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
Could you write manuall for migration from 7 to 8 version #1040
Comments
Sounds like a great opportunity for user contribution! |
To me, it sounds like something that should be defined in a changelog, as you kinda need to know the project very well and understand what changed from 7 to 8. |
The change is too large. The migration works seems very heavy. |
I'm still using |
How to let the following code work on import NextI18Next from 'next-i18next';
import path from 'path';
const NextI18NextInstance = new NextI18Next({
defaultLanguage: 'en-US',
otherLanguages: ['zh-CN'],
localePath: path.resolve('./public/static/locales'),
shallowRender: true,
detection: { cookieMinutes: 60 * 24 * 365 },
});
export default NextI18NextInstance;
export const {
appWithTranslation,
withTranslation,
} = NextI18NextInstance; |
Out legacy code uses classes, which prevents us from using hooks. |
First paragraph of the manual:
|
I have migrated it from v7 to v8. It takes me a whole day. It seems that next.js and next-i18next are not friendly with class components. |
The key to the migration is as the following: const Index = PageWrapper(Users);
export default Index;
export const getServerSideProps = async (ctx) => {
const result = await Index.WrappedComponent.getInitialProps(ctx);
return {
props: {
...await serverSideTranslations(ctx.locale, ['common']),
...result,
},
};
}; Since we can't use |
Finally, we don't use onChange={({ option }) => router.replace(router.pathname, router.pathname, { locale: option.value })} |
Please migrate your components away from |
Previously, I could use i18n in non-components using new NextI18Next. How can we create a new instance now? |
@vechnii2007 You can do: import { i18n } from 'next-i18next' |
in console.log(i18n) have null |
const { i18n } = require("./next-i18next.config"); in next.config.js
in next-i18next.config.js in App component
But i have another outside file, store.ts, where i used i18n from config file
|
That would be a lot of work. We can't finish it in a short time. |
Hello, Do you have any indications on how to migrate the NextJs error files?
That error code doesn't seem to be available inside of getStaticProps. |
This comment has been minimized.
This comment has been minimized.
I am not sure how your PageWrapper is defined, and I cannot use getServerSideProps on the _error page. |
how use globali18n if we haven't access to global i18n ? |
Im also in the process of migration from v7 to v8. Hasn't been a smooth ride for the past few days. Few things I learnt the hard way. These pointers might help to be included in the manual
There was a thread in nextjs repo to as a possible workaround, export function withCommonServerSideProps(customSeversidePropsFn, opts) {
return async function f(appContext) {
// ...your common code here
let props = { };
let customFnProps = { props: {} };
if (customSeversidePropsFn) {
customFnProps = await customSeversidePropsFn(appContext, props);
props = {
...props,
...customFnProps.props,
};
}
return {
props: { ...JSON.parse(JSON.stringify(props)) },
};
};
} pages/index.js import { withCommonServerSideProps } from './withCommonServerSideProps';
//...your page component code
export const getServerSideProps = withCommonServerSideProps(
async (appContext, commonProps) => {
const i18nextProps = await serverSideTranslations(
'nl-NL',
['common'],
);
return { props: {...i18nextProps} };
},
{ },
);
return {
props: { ...JSON.parse(JSON.stringify(props)) },
}; If not you will run into another error in the lines of undefined cannot be parsed
My migration is not over yet, but these were some of the worst ones, I will update this thread if find any further in to the task. Hope this helps someone!! |
@isaachinman, what with this trouble(bug)? lib doesn't work properly? do you plan to fix it? |
It's not a bug, the |
I would like to reiterate for any users who are new to NextJs, that you should be using |
@ruhaim you write "If I keep having the same error you mention (but from use with Edit: just saw @isaachinman's comment: answer is should be possible :) Doesnt resolve my error though. I am not calling it anywhere outside |
can u show example how can init i18n, when we build project, and need instance i18n not pages or components |
You need to call serverSideTranslations() directly within
getServerSideProps() or getStaicProps(). If you call serverSideTranslations()
via a wrapper method, then you confront the error.
In other words the serverSideTranslations import should be on a page level
component. Never in an inner component
…On Fri, 19 Mar 2021, 19:15 Annemarie Beemsterboer, ***@***.***> wrote:
@ruhaim <https://github.com/ruhaim> you write "If serverSideTranslations()
is called from anywhere else, NextJS will not build or pesky runtime error
will keep showing.". The README mentions it should also be possible from
getStaticProps, did you purposefully exclude it?
I keep having the same error you mention (but from use with getStaticProps
)
ModuleNotFoundError: Module not found: Error: Can't resolve 'fs' in
'/node_modules/next-i18next/dist/commonjs'
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1040 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AA6GWAVOVCUHGFXUNRGUAUDTENIORANCNFSM4YZJFWEQ>
.
|
where i can do the initialization of i18n, except gSSp, gSP? |
That is exactly where it is initialised. Please feel free to check out the source code. |
@annbeemsterboer Could you check if there is an unused reference or an import to |
This comment has been minimized.
This comment has been minimized.
why this offtopic? @isaachinman we ask a normal question, how to get access to i18n instance from another file, not page or component? i mean this |
I'm going to go out on a limb and say it was marked as off-topic because it was hostile. This project is amazing and really helps when it comes to adding i18n to a Nextjs application and some of ya'll are being pretty demanding without offering a whole lot of support. Open source only works when other people contribute. If you can't become a sponsor (how are there only 4 sponsors?!?!) you should, at a minimum, consider contributing documentation, adding to the README, etc. The absolute worst thing you can do is to to be antagonistic or hostile. We get it. You have a job to do and you'd like for it to be as easy as possible. We all do. Get over it. You want to write a library to support i18n on Nextjs from scratch? Me either. Ya'll really expect @isaachinman to maintain the library, write all the documentation, keep up with the incredibly fast pace of the Nextjs team's changes, write migration guides, answer all your questions in a timely manner AND deal with hostile comments? For free?
Then write one yourself & make it available to the community. You are not entitled to anything. I think he has been pretty clear in this and in other issues. @ruhaim's comment above is especially helpful. I've only been playing around with the library for ~ 24 hours, but my understanding is the following (feel free to fact check me if any of this is incorrect):
TL;DR - Be nice. Go sponsor the project. |
Hey @austinhale – thanks for the write up, and I appreciate the sentiment. Open source software is largely thankless work – that's just the way it is. Your comments are all spot on, and I think they will be very helpful to other users. I would like to point out a few other things:
Also, I'm not sure I understand your eighth point – do you mind opening an issue for that one? You should be able to call @vechnii2007 The We are all software developers – don't be afraid of reading the source code. |
@austinhale @isaachinman Thanks guys for good answer. Sorry if i hurt your feelings. |
@isaachinman
now such an entry does not work, I looked in the code and found that in |
@vechnii2007 Although that check is just to ensure |
This comment has been minimized.
This comment has been minimized.
@ruhaim indeed this was my issue, I was using it in on a component level in addition to page level. Thanks for the info! |
This comment has been minimized.
This comment has been minimized.
@vaniyokk As previously stated, if you want to continue using The |
If you needs to keep using getInitialProps and requires continuous support and patches of i18n support, I would recommend switching to next-translate as they still keep supporting getInitialProps |
I'd like to stress that currently the only reason to use |
@isaachinman |
@Shariaty This is specifically covered in the documentation:
|
@isaachinman When both are required, It means that useTranslation hook wont work without serverSideTranslations and serverSideTranslations should be implemented in each and every page in order to useTranslation which is used inside header layout shared among all pages works ? |
Yes, that is correct. |
@austinhale I just wanted to say that your reply saved me tons of time and frustration! Everyone should know about this comment. Thank you. |
Could someone help me and tell me what is the equivalence of @isaachinman In the basic example you shared in the documentation, you show just one approach with the Link tag and locale. It would be great to show other possibilities like doing dynamically in a component by calling a function. I am happy to contribute and help with the documentation if you need it. |
@gcaggia As stated previously, NextJs handles i18n routing internally. |
Maybe this helps. That's a function where you can call everywhere:
|
Here a little summary what I did to migrate quite a large app. My project env:
Generally. I have quite a complex app where we use, phraseInContextEditor, translated data depending on locale from the DB and multilanguage sometimes depending on the ENV. Said that, it now works after around 1 day of work. So I'm sure most applications can be migrated quite easily. Just read carefully the docs and the issues section here. |
@isaachinman If I'd write the manual where should I do it, on the readme? |
@samfromaway No, I think we'd want a separate |
Hello everyone. I was looking for manual for migration but i don't found. Could you pls write
The text was updated successfully, but these errors were encountered: