-
-
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
fix: issue #1040 #1238
fix: issue #1040 #1238
Conversation
A migration guide for this issue #1040.
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/isaachinman/next-i18next/52XRt5QedN2PrJJdGMwe5AtooZS6 |
Fix: issue #1040
v8-migration.md
Outdated
Please read the [full documentation](https://github.com/isaachinman/next-i18next/blob/master/README.md), before migrating from previous versions to v8. | ||
|
||
This is a guide which will cover most use cases to migrate from v7 to v8. | ||
We advise migrating as soon as possible, as new versions of next.js won't be compatible with the v7 of this package next-i18next. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We advise migrating as soon as possible, as new versions of next.js won't be compatible with the v7 of this package next-i18next. | |
We advise migrating as soon as possible, as new versions of NextJs won't be compatible with the v7 of this package `next-i18next`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed with new commit
v8-migration.md
Outdated
We advise migrating as soon as possible, as new versions of next.js won't be compatible with the v7 of this package next-i18next. | ||
|
||
#### What is new? | ||
This library, next-i18next, has changed a lot because it now is NOT providing internationalized routing anymore, as [next.js is providing that now.](https://nextjs.org/docs/advanced-features/i18n-routing) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This library, next-i18next, has changed a lot because it now is NOT providing internationalized routing anymore, as [next.js is providing that now.](https://nextjs.org/docs/advanced-features/i18n-routing) | |
This package, `next-i18next`, has changed a lot because it now is_not_ providing internationalised routing, as [NextJs has first class support for it.](https://nextjs.org/docs/advanced-features/i18n-routing) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed with new commit
v8-migration.md
Outdated
#### What is new? | ||
This library, next-i18next, has changed a lot because it now is NOT providing internationalized routing anymore, as [next.js is providing that now.](https://nextjs.org/docs/advanced-features/i18n-routing) | ||
|
||
Before the translation functionality was initialized on a global level, in the page `_app.js`. Now you have to import the functionality with a new method `serverSideTranslations` on EACH page in your next pages folder where you have translations. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before the translation functionality was initialized on a global level, in the page `_app.js`. Now you have to import the functionality with a new method `serverSideTranslations` on EACH page in your next pages folder where you have translations. | |
Before the translation functionality was initialised on a global level, in `_app.js`. Now, you must use a new method, called `serverSideTranslations` on_each_ page in your `pages` directory. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed with new commit
v8-migration.md
Outdated
|
||
Before the translation functionality was initialized on a global level, in the page `_app.js`. Now you have to import the functionality with a new method `serverSideTranslations` on EACH page in your next pages folder where you have translations. | ||
|
||
The object `i18n` which was imported directly from `i18n.js` in the v7 suppored only client-side-rendering. Now in the v8 the `i18n` object also supports server-side-renering. So you can use the `i18n.language` for server side rendered elements. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The object `i18n` which was imported directly from `i18n.js` in the v7 suppored only client-side-rendering. Now in the v8 the `i18n` object also supports server-side-renering. So you can use the `i18n.language` for server side rendered elements. | |
The object `i18n` which was imported directly from `i18n.js` in `next-i18next@<8` suppored only client-side-rendering. Now in the v8 the `i18n` object also supports server-side rendering. So you can use the `i18n.language` for server-side rendered elements. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed with new commit
v8-migration.md
Outdated
1. `appWithTranslation` is still wrapping the App in `_app.js`. | ||
2. `withTranslation` is still working the same way. | ||
3. `useTranslation` is still working the same way. | ||
4. The [translation content structure](https://github.com/isaachinman/next-i18next/blob/master/README.md#2-translation-content) is still the same. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1. `appWithTranslation` is still wrapping the App in `_app.js`. | |
2. `withTranslation` is still working the same way. | |
3. `useTranslation` is still working the same way. | |
4. The [translation content structure](https://github.com/isaachinman/next-i18next/blob/master/README.md#2-translation-content) is still the same. | |
1. `appWithTranslation` still wraps the App in `_app.js` | |
2. `withTranslation` works the same way | |
3. `useTranslation` works the same way | |
4. The [translation content structure](https://github.com/isaachinman/next-i18next/blob/master/README.md#2-translation-content) remains the same |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed with new commit
v8-migration.md
Outdated
1. Remove i18n.js and add next-i18next.config.js like described in [the docs](https://github.com/isaachinman/next-i18next#3-project-setup) to the next.config.js file. | ||
2. Replace `import { appWithTranslation } from 'i18n'` with `import { appWithTranslation } from 'next-i18next'` | ||
3. Replace all instances of `import { withTranslation } from 'i18n` to `import { withTranslation } from 'next-i18next'` | ||
4. Replace all instances of `import { useTranslation } from 'i18n` to `import { useTranslation } from 'next-i18next'` | ||
5. Add to `getServerSideProps` or `getInitialProps` in the return as props`...(await serverSideTranslations(locale, [<YOUR_NAMESPACES>]))` in every single page where you have translations in children. Or in all pages if you have a component in `_app.js` that needs translations. As [described in the docs.](https://github.com/isaachinman/next-i18next#serversidetranslations) | ||
6. Remove `namespacesRequired: ['common'],` in `_app.js` (not used anymore). | ||
7. Change the language changer to `router.push(router.asPath, undefined, { locale: <YOUR_LOCALE>, });` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1. Remove i18n.js and add next-i18next.config.js like described in [the docs](https://github.com/isaachinman/next-i18next#3-project-setup) to the next.config.js file. | |
2. Replace `import { appWithTranslation } from 'i18n'` with `import { appWithTranslation } from 'next-i18next'` | |
3. Replace all instances of `import { withTranslation } from 'i18n` to `import { withTranslation } from 'next-i18next'` | |
4. Replace all instances of `import { useTranslation } from 'i18n` to `import { useTranslation } from 'next-i18next'` | |
5. Add to `getServerSideProps` or `getInitialProps` in the return as props`...(await serverSideTranslations(locale, [<YOUR_NAMESPACES>]))` in every single page where you have translations in children. Or in all pages if you have a component in `_app.js` that needs translations. As [described in the docs.](https://github.com/isaachinman/next-i18next#serversidetranslations) | |
6. Remove `namespacesRequired: ['common'],` in `_app.js` (not used anymore). | |
7. Change the language changer to `router.push(router.asPath, undefined, { locale: <YOUR_LOCALE>, });` | |
1. Remove `i18n.js` and add `next-i18next.config.js` as described in [the docs](https://github.com/isaachinman/next-i18next#3-project-setup) to your `next.config.js` file | |
2. Replace `import { appWithTranslation } from 'i18n'` with `import { appWithTranslation } from 'next-i18next'` | |
3. Replace all instances of `import { withTranslation } from 'i18n` to `import { withTranslation } from 'next-i18next'` | |
4. Replace all instances of `import { useTranslation } from 'i18n` to `import { useTranslation } from 'next-i18next'` | |
5. Add to `getServerSideProps` or `getInitialProps` in the return as props`...(await serverSideTranslations(locale, [<YOUR_NAMESPACES>]))` in every single page where you have translations. Note that if you have a component in `_app` that needs translations, you will have to do this for _all_ pages. Follow [the docs.](https://github.com/isaachinman/next-i18next#serversidetranslations) | |
6. Remove `namespacesRequired: ['common'],` in `_app.js` (not used anymore) | |
7. To change language imperatively, you can now do: `router.push(router.asPath, undefined, { locale: <YOUR_LOCALE>, });` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed with new commit
v8-migration.md
Outdated
1. Add to the custom 404 page the `...(await serverSideTranslations(locale, [<YOUR_NAMESPACES>])),` as a return in props in `getStaticProps` so the 404 page works with translations as well. | ||
2. Add to the custom 500 page the `...(await serverSideTranslations(locale, [<YOUR_NAMESPACES>])),` as a return in props in `getStaticProps` so the 404 page works with translations as well. | ||
3. Add set cookie `NEXT_LOCALE` for language recognition, More about that in [the next.js docs](https://nextjs.org/docs/advanced-features/i18n-routing#leveraging-the-next_locale-cookie) | ||
4. Adjust the Jest test settings to mock `withTranslation`,`useTranslation`, and `t()` or/and `i18n` in props. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1. Add to the custom 404 page the `...(await serverSideTranslations(locale, [<YOUR_NAMESPACES>])),` as a return in props in `getStaticProps` so the 404 page works with translations as well. | |
2. Add to the custom 500 page the `...(await serverSideTranslations(locale, [<YOUR_NAMESPACES>])),` as a return in props in `getStaticProps` so the 404 page works with translations as well. | |
3. Add set cookie `NEXT_LOCALE` for language recognition, More about that in [the next.js docs](https://nextjs.org/docs/advanced-features/i18n-routing#leveraging-the-next_locale-cookie) | |
4. Adjust the Jest test settings to mock `withTranslation`,`useTranslation`, and `t()` or/and `i18n` in props. | |
1. Add to the custom 404 page the `...(await serverSideTranslations(locale, [<YOUR_NAMESPACES>])),` as a return in props in `getStaticProps` so the 404 page works with translations as well | |
2. Add to the custom 500 page the `...(await serverSideTranslations(locale, [<YOUR_NAMESPACES>])),` as a return in props in `getStaticProps` so the 404 page works with translations as well | |
3. Add set cookie `NEXT_LOCALE` for language recognition. More about that in [the NextJs docs](https://nextjs.org/docs/advanced-features/i18n-routing#leveraging-the-next_locale-cookie) | |
4. Adjust the Jest test settings to mock `withTranslation`,`useTranslation`, and `t()` or/and `i18n` in props. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed with new commit
Corrections according to issachinman Please let me know where in the "main" readme to link this md file. Or you can add it yourself.
@isaachinman All fixed. Only things that's missing is the link on the main readme |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. Can we create a top-level docs
directory and put this inside, and link to it from the main README?
Sorry I accidentaly delete my fork I added a new PR #1254 |
Sorry I accidentally delete my fork I added a new PR #1254 |
A migration guide for this issue #1040.