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

Support i18next 22, react-i18next 12 and move both to peer-deps #1966

Merged
merged 29 commits into from Oct 26, 2022
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
43d7a83
chore(deps): update to i18next ^22.0.0
belgattitude Oct 19, 2022
1653be1
chore: more react-i18next i18next to peer deps
belgattitude Oct 20, 2022
b82d6c2
docs: update installation for peer-dependencies
belgattitude Oct 20, 2022
6ac538b
docs: added UPGRADING notes
belgattitude Oct 20, 2022
40ce20d
docs: add upgrading
belgattitude Oct 20, 2022
6819783
docs: update upgrade notes
belgattitude Oct 20, 2022
310ed5a
Merge branch 'master' into update-i18next-22
belgattitude Oct 20, 2022
d96ced8
chore(deps): update example to react-i18next v12
belgattitude Oct 20, 2022
a103a0b
docs: changelog
belgattitude Oct 20, 2022
394675c
Merge branch 'master' into update-i18next-22
belgattitude Oct 20, 2022
2f64ff5
refactor!: drop export of Resources
belgattitude Oct 20, 2022
3d06e5f
Merge branch 'master' into update-i18next-22
belgattitude Oct 21, 2022
dd35ecf
chore(deps): update to i18next 22.0.2
belgattitude Oct 21, 2022
a8a05cf
chore(peer-deps): remove range and min i18next to 22.0.2
belgattitude Oct 21, 2022
1063789
feat(example): example on i18next new translation key
belgattitude Oct 21, 2022
91467ac
fix(examples): restore current way for keys typing
belgattitude Oct 21, 2022
46aba9a
Merge branch 'master' into update-i18next-22
belgattitude Oct 21, 2022
0d873f9
docs: changelog and upgrading updates
belgattitude Oct 21, 2022
98fe8bf
docs: rephrase
belgattitude Oct 21, 2022
c453ac2
Add @belgattitude as a contributor
belgattitude Oct 21, 2022
4369cd1
Merge branch 'master' into update-i18next-22
belgattitude Oct 26, 2022
062f4df
refactor: remove i18next type augmentation
belgattitude Oct 26, 2022
da82db5
Merge remote-tracking branch 'origin/master'
belgattitude Oct 26, 2022
195fc49
Merge branch 'master' into update-i18next-22
belgattitude Oct 26, 2022
b37086c
revert: lost range during merges
belgattitude Oct 26, 2022
1db5b73
Merge remote-tracking branch 'origin/master'
belgattitude Oct 26, 2022
b565be4
Merge remote-tracking branch 'origin/master'
belgattitude Oct 26, 2022
5243ae9
Merge branch 'master' into update-i18next-22
belgattitude Oct 26, 2022
f94278d
chore(deps): update to i18next-fs-backend@^2.0.0
belgattitude Oct 26, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 17 additions & 1 deletion CHANGELOG.md
@@ -1,6 +1,22 @@
## next

- breaking: drop nextjs < 12.0.0 and react < 17.0.2 in [#1983](https://github.com/i18next/next-i18next/pull/1983)
Although it is a major, existing code should not be impacted. Only the install.
Read also the [UPGRADING](https://github.com/i18next/next-i18next/blob/master/UPGRADING.md) document
to know more.

- **breaking**: react-i18next and i18next are now peer-dependencies and must be installed
in the consuming app, see [#1966](https://github.com/i18next/next-i18next/pull/1966)

```bash
npm install react-i18next i18next --save # NPM
yarn add react-i18next i18next # Yarn
pnpm add react-i18next i18next --save # PNPM
```

If you encounter any issue, please read the [Troubleshoot](https://github.com/i18next/next-i18next/blob/master/TROUBLESHOOT.md) doc.

- **new:**: Upgrade to [i18next v22](https://github.com/i18next/i18next/releases) and react-i18next v12, see [#1966](https://github.com/i18next/next-i18next/pull/1966)
- **breaking**: drop nextjs < 12.0.0 and react < 17.0.2 in [#1983](https://github.com/i18next/next-i18next/pull/1983)
- breaking: drop node 12.x support, requires 14.x. Recommended minimum to `^14.13.1`,
see [#1974](https://github.com/i18next/next-i18next/pull/1974)

Expand Down
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -41,8 +41,8 @@ Now our Next.js app is fully translatable!

### 1. Installation

```jsx
yarn add next-i18next
```bash
yarn add next-i18next react-i18next i18next
```

You need to also have `react` and `next` installed.
Expand Down
16 changes: 16 additions & 0 deletions UPGRADING.md
@@ -0,0 +1,16 @@
## Version 13.x

Both `i18next` and `react-i18next` have been moved to [peerDependencies](https://github.com/npm/rfcs/blob/main/implemented/0030-no-install-optional-peer-deps.md)
and must be installed part of `next-i18next`. When upgrading don't forget to add them to your dependencies:

```bash
npm install react-i18next i18next --save # NPM
yarn add react-i18next i18next # Yarn
pnpm add react-i18next i18next --save # PNPM
```

This move was done in the hope to avoid issues regarding duplicates. See the
[TROUBLESHOOT](https://github.com/i18next/next-i18next/blob/master/TROUBLESHOOT.md#multiple-instances)
for more info. In the future it will also allow to support multiple ranges.


2 changes: 2 additions & 0 deletions examples/simple/package.json
Expand Up @@ -9,9 +9,11 @@
"start": "next start -p ${PORT:=3000}"
},
"dependencies": {
"i18next": "22.0.2",
"next": "12.3.1",
"next-i18next": "12.1.0",
"react": "18.2.0",
"react-i18next": "12.0.0",
"react-dom": "18.2.0"
},
"devDependencies": {
Expand Down
25 changes: 25 additions & 0 deletions examples/simple/types.d/i18next.d.ts.future
@@ -0,0 +1,25 @@
/**
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adrai testing upstream i18next 22 and types changes.

I tried to move the declare module 'react-i18next' to declare module 'i18next', but actually it does not work (it's ignored). The current declare module 'react-i18next' still works perfect.

I guess if we're going only to v22... we might have to change few things (outside of scope of this P/R)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe @pedrodurek can advice?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rosskevin are you more familiar with next.js?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't use i18next and haven't been following specific changes closely. It's probably best for @pedrodurek to advise on the aspects of the custom types changes here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree.

@adrai as it seems to work without the change. I propose to remove this file and finalize this pr. Can be done in a subsequent pr.

Wdyt ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean using the new i18next and react-i18next version but without the i18next.d.ts file?
If @pedrodurek can confirm this, yes.
I don't like to create another next-i18next major afterwards if this is not ok.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree. just to bring some findings... I think it's safe though.

Existing types augmentations works and handled from react-i18next not next-i18next.

Totally fine to wait for me. Thx

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @belgattitude
You should change the import at the scope of the file, otherwise I won't re-export the other types from i18next.
import 'i18next' instead of import 'react-i18next'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pedrodurek Thanks, I did the change but still no luck.

I feel there's some more changes to do. I propose this:

  1. Extract this part to another P/R (see Refactor example types to i18next v22 (do not merge) #1994), so we can work in isolation.
  2. Make this PR mergable (for now it will work based on react-i18next.d.ts) - Done.

You'll find explanations, issues where we can reproduce #1994.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll finish addressing some other issues that were reported and will look into it right after

* If you want to enable locale keys typechecking and enhance IDE experience.
*
* Requires `resolveJsonModule:true` in your tsconfig.json.
*
* @link https://www.i18next.com/overview/typescript
*/
import 'react-i18next'

import type common from '../public/locales/en/common.json'
import type footer from '../public/locales/en/footer.json'
import type secondPage from '../public/locales/en/second-page.json'

interface I18nNamespaces {
common: typeof common
footer: typeof footer
'second-page': typeof secondPage
}

declare module 'i18next' {
interface CustomTypeOptions {
defaultNS: 'common'
resources: I18nNamespaces
}
}
7 changes: 4 additions & 3 deletions examples/simple/types.d/react-i18next.d.ts
@@ -1,7 +1,8 @@
/**
* Types augmentation for translation keys to allow to typecheck
* and suggesting keys to the t function. In case it's too slow
* you can opt out by commenting the following code.
* If you want to enable locale keys typechecking and enhance IDE experience.
*
* Requires `resolveJsonModule:true` in your tsconfig.json.
*
* @link https://www.i18next.com/overview/typescript
*/
import 'react-i18next'
Expand Down
6 changes: 5 additions & 1 deletion examples/ssg/package.json
Expand Up @@ -15,9 +15,13 @@
"downloadLocales": "locize download --project-id=0842ada9-1d1d-4d48-ab27-08f6a132f558 --ver=latest --clean=true --path=./public/locales"
},
"dependencies": {
"i18next": "22.0.2",
"next": "12.3.1",
"next-i18next": "12.1.0",
"next-language-detector": "1.0.2"
"next-language-detector": "1.0.2",
"react": "18.2.0",
"react-i18next": "12.0.0",
"react-dom": "18.2.0"
},
"devDependencies": {
"eslint-config-next": "12.3.1",
Expand Down
12 changes: 7 additions & 5 deletions package.json
Expand Up @@ -127,12 +127,14 @@
"eslint-plugin-typescript-sort-keys": "^2.1.0",
"gh-release": "6.0.4",
"husky": "^3.0.0",
"i18next": "^22.0.2",
"jest": "^26.6.3",
"next": "^12.2.5",
"npm-run-all": "^4.1.5",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"size-limit": "8.1.0",
"react-i18next": "^12.0.0",
"start-server-and-test": "^1.14.0",
"typescript": "^4.7.4",
"webpack": "5.74.0"
Expand All @@ -142,12 +144,12 @@
"@types/hoist-non-react-statics": "^3.3.1",
"core-js": "^3",
"hoist-non-react-statics": "^3.3.2",
"i18next": "^21.9.1",
"i18next-fs-backend": "^1.1.5",
"react-i18next": "^11.18.4"
"i18next-fs-backend": "^1.1.5"
},
"peerDependencies": {
"next": ">= 12.0.0",
"react": ">= 17.0.2"
"i18next": "^22.0.2",
"next": ">= 10.0.0",
"react": ">= 16.8.0",
"react-i18next": "^12.0.0"
}
}
2 changes: 0 additions & 2 deletions src/types.ts
Expand Up @@ -5,7 +5,6 @@ import {
Trans,
withTranslation,
WithTranslation as ReactI18nextWithTranslation,
Resources,
DefaultNamespace,
Translation,
} from 'react-i18next'
Expand Down Expand Up @@ -64,6 +63,5 @@ export {
Trans,
Translation,
withTranslation,
Resources,
DefaultNamespace,
}