Skip to content

Commit

Permalink
feat: support i18next v22 type augmentation (#1997)
Browse files Browse the repository at this point in the history
  • Loading branch information
belgattitude committed Nov 6, 2022
1 parent 5e65ee2 commit 7464c65
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 16 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,6 @@ cypress.json

# npm
package-lock.json

# typescript
tsconfig.tsbuildinfo
9 changes: 5 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ to know more.

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`,
- **breaking**: Types augmentation is now handled by i18next instead of react-i18next, see [#1997](https://github.com/i18next/next-i18next/pull/1997)
- **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)
- fix: Fix types for appWithTranslation [#1987](https://github.com/i18next/next-i18next/pull/1987)
- **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)
- **fix**: Fix types for appWithTranslation [#1987](https://github.com/i18next/next-i18next/pull/1987)

## 12.1.0

Expand Down
35 changes: 31 additions & 4 deletions UPGRADING.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
## Version 13.x
## Version 13.0.0

Version 13.0.0 comes with 2 breaking changes in order to improve developer experience and
stability.

### New installation requirements

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:
Expand All @@ -9,8 +14,30 @@ 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.
Minimum versions supported are `i18next@^22.0.3` and `react-i18next@^12.0.0`.

This move was done in the hope to avoid issues regarding duplicates. In case of issue when
uĝrading, see the [TROUBLESHOOT](https://github.com/i18next/next-i18next/blob/master/TROUBLESHOOT.md#multiple-instances)
to ensure peer-dependencies are properly installed.

### Keys typings

If you're using typescript type augmentation for your locale keys, they've been moved from `react-i18next` to [i18next](https://www.i18next.com/overview/typescript).
Rename `@types/react-i18next.d.ts` to `@types/i18next.d.ts` and be sure to update the imports:

```typescript
import 'i18next';
import type common from '../public/locales/en/common.json';
import type other from '../public/locales/en/other.json';

interface I18nNamespaces {
common: typeof common,
other: typeof other,
}
declare module 'i18next' {
interface CustomTypeOptions {
defaultNS: 'common',
resources: I18nNamespaces,
}
}
```
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@
*
* @link https://www.i18next.com/overview/typescript
*/
import 'react-i18next'
import '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
common: typeof common
footer: typeof footer
'second-page': typeof secondPage
}

declare module 'react-i18next' {
declare module 'i18next' {
interface CustomTypeOptions {
defaultNS: 'common'
resources: I18nNamespaces
Expand Down
7 changes: 4 additions & 3 deletions examples/simple/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
"scripts": {
"dev": "next",
"build": "next build",
"start": "next start -p ${PORT:=3000}"
"start": "next start -p ${PORT:=3000}",
"typecheck": "tsc --project ./tsconfig.json --noEmit"
},
"dependencies": {
"i18next": "22.0.3",
"next": "13.0.0",
"i18next": "22.0.4",
"next": "13.0.2",
"next-i18next": "12.1.0",
"react": "18.2.0",
"react-i18next": "12.0.0",
Expand Down

0 comments on commit 7464c65

Please sign in to comment.