next-i18next 8.8.0 → 9.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -0
- package/dist/commonjs/appWithTranslation.js +7 -4
- package/dist/commonjs/serverSideTranslations.js +1 -0
- package/dist/es/appWithTranslation.js +5 -5
- package/dist/es/serverSideTranslations.js +1 -0
- package/dist/esm/appWithTranslation.js +7 -4
- package/dist/esm/serverSideTranslations.js +1 -0
- package/dist/types/appWithTranslation.d.ts +1 -1
- package/dist/types/types.d.ts +1 -0
- package/package.json +8 -5
package/README.md
CHANGED
|
@@ -236,6 +236,24 @@ This option will reload your translations whenever `serverSideTranslations` is c
|
|
|
236
236
|
|
|
237
237
|
All other [i18next options](https://www.i18next.com/overview/configuration-options) can be passed in as well.
|
|
238
238
|
|
|
239
|
+
#### Loading Namespaces Dynamically Client Side
|
|
240
|
+
|
|
241
|
+
In some use cases, you might want to load a translation file dynamically without having to use `serverSideTranslations`. This can be especially useful for lazy-loaded components that you don't want slowing down pages.
|
|
242
|
+
|
|
243
|
+
This can easily be done by using [addResourceBundle](https://www.i18next.com/how-to/add-or-load-translations#add-after-init):
|
|
244
|
+
|
|
245
|
+
```tsx
|
|
246
|
+
import { i18n } from 'next-i18next'
|
|
247
|
+
|
|
248
|
+
const Component = () => {
|
|
249
|
+
const { locale } = useRouter()
|
|
250
|
+
|
|
251
|
+
useEffect(() => {
|
|
252
|
+
i18n.addResourceBundle(locale, '<namespace name>')
|
|
253
|
+
}, [])
|
|
254
|
+
}
|
|
255
|
+
```
|
|
256
|
+
|
|
239
257
|
## Migration to v8
|
|
240
258
|
|
|
241
259
|
To migrate from previous versions to the version 8, check out the [v8-migration guide](https://github.com/isaachinman/next-i18next/tree/master/docs/v8-migration.md)
|
|
@@ -86,17 +86,20 @@ var appWithTranslation = function appWithTranslation(WrappedComponent) {
|
|
|
86
86
|
var configOverride = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
87
87
|
|
|
88
88
|
var AppWithTranslation = function AppWithTranslation(props) {
|
|
89
|
-
var
|
|
90
|
-
|
|
89
|
+
var _ref = props.pageProps,
|
|
90
|
+
_nextI18Next = _ref._nextI18Next;
|
|
91
|
+
var locale = null; // Memoize the instance and only re-initialize when either:
|
|
91
92
|
// 1. The route changes (non-shallowly)
|
|
92
93
|
// 2. Router locale changes
|
|
93
94
|
|
|
94
95
|
var i18n = (0, _react.useMemo)(function () {
|
|
95
96
|
var _userConfig;
|
|
96
97
|
|
|
97
|
-
if (!
|
|
98
|
+
if (!_nextI18Next) return null;
|
|
98
99
|
var userConfig = _nextI18Next.userConfig;
|
|
99
|
-
var initialI18nStore = _nextI18Next.initialI18nStore
|
|
100
|
+
var initialI18nStore = _nextI18Next.initialI18nStore,
|
|
101
|
+
initialLocale = _nextI18Next.initialLocale;
|
|
102
|
+
locale = initialLocale;
|
|
100
103
|
|
|
101
104
|
if (userConfig === null && configOverride === null) {
|
|
102
105
|
throw new Error('appWithTranslation was called without a next-i18next config');
|
|
@@ -243,6 +243,7 @@ var serverSideTranslations = /*#__PURE__*/function () {
|
|
|
243
243
|
return _context.abrupt("return", {
|
|
244
244
|
_nextI18Next: {
|
|
245
245
|
initialI18nStore: initialI18nStore,
|
|
246
|
+
initialLocale: initialLocale,
|
|
246
247
|
userConfig: config.serializeConfig ? userConfig : null
|
|
247
248
|
}
|
|
248
249
|
});
|
|
@@ -12,22 +12,22 @@ export const appWithTranslation = (WrappedComponent, configOverride = null) => {
|
|
|
12
12
|
const {
|
|
13
13
|
_nextI18Next
|
|
14
14
|
} = props.pageProps;
|
|
15
|
-
|
|
16
|
-
locale
|
|
17
|
-
} = props.router; // Memoize the instance and only re-initialize when either:
|
|
15
|
+
let locale = null; // Memoize the instance and only re-initialize when either:
|
|
18
16
|
// 1. The route changes (non-shallowly)
|
|
19
17
|
// 2. Router locale changes
|
|
20
18
|
|
|
21
19
|
const i18n = useMemo(() => {
|
|
22
20
|
var _userConfig;
|
|
23
21
|
|
|
24
|
-
if (!
|
|
22
|
+
if (!_nextI18Next) return null;
|
|
25
23
|
let {
|
|
26
24
|
userConfig
|
|
27
25
|
} = _nextI18Next;
|
|
28
26
|
const {
|
|
29
|
-
initialI18nStore
|
|
27
|
+
initialI18nStore,
|
|
28
|
+
initialLocale
|
|
30
29
|
} = _nextI18Next;
|
|
30
|
+
locale = initialLocale;
|
|
31
31
|
|
|
32
32
|
if (userConfig === null && configOverride === null) {
|
|
33
33
|
throw new Error('appWithTranslation was called without a next-i18next config');
|
|
@@ -17,17 +17,20 @@ export var appWithTranslation = function appWithTranslation(WrappedComponent) {
|
|
|
17
17
|
var configOverride = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
18
18
|
|
|
19
19
|
var AppWithTranslation = function AppWithTranslation(props) {
|
|
20
|
-
var
|
|
21
|
-
|
|
20
|
+
var _ref = props.pageProps,
|
|
21
|
+
_nextI18Next = _ref._nextI18Next;
|
|
22
|
+
var locale = null; // Memoize the instance and only re-initialize when either:
|
|
22
23
|
// 1. The route changes (non-shallowly)
|
|
23
24
|
// 2. Router locale changes
|
|
24
25
|
|
|
25
26
|
var i18n = useMemo(function () {
|
|
26
27
|
var _userConfig;
|
|
27
28
|
|
|
28
|
-
if (!
|
|
29
|
+
if (!_nextI18Next) return null;
|
|
29
30
|
var userConfig = _nextI18Next.userConfig;
|
|
30
|
-
var initialI18nStore = _nextI18Next.initialI18nStore
|
|
31
|
+
var initialI18nStore = _nextI18Next.initialI18nStore,
|
|
32
|
+
initialLocale = _nextI18Next.initialLocale;
|
|
33
|
+
locale = initialLocale;
|
|
31
34
|
|
|
32
35
|
if (userConfig === null && configOverride === null) {
|
|
33
36
|
throw new Error('appWithTranslation was called without a next-i18next config');
|
|
@@ -161,6 +161,7 @@ export var serverSideTranslations = /*#__PURE__*/function () {
|
|
|
161
161
|
return _context.abrupt("return", {
|
|
162
162
|
_nextI18Next: {
|
|
163
163
|
initialI18nStore: initialI18nStore,
|
|
164
|
+
initialLocale: initialLocale,
|
|
164
165
|
userConfig: config.serializeConfig ? userConfig : null
|
|
165
166
|
}
|
|
166
167
|
});
|
|
@@ -8,4 +8,4 @@ declare type AppProps = NextJsAppProps & {
|
|
|
8
8
|
pageProps: SSRConfig;
|
|
9
9
|
};
|
|
10
10
|
export declare let globalI18n: I18NextClient | null;
|
|
11
|
-
export declare const appWithTranslation: (WrappedComponent: React.ComponentType<
|
|
11
|
+
export declare const appWithTranslation: <Props extends AppProps = AppProps>(WrappedComponent: React.ComponentType<Props>, configOverride?: UserConfig | null) => ((props: Props) => JSX.Element) & hoistNonReactStatics.NonReactStatics<React.ComponentType<Props>, {}>;
|
package/dist/types/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "next-i18next",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "9.0.1",
|
|
4
4
|
"repository": "git@github.com:isaachinman/next-i18next.git",
|
|
5
5
|
"author": "Isaac Hinman <isaac@isaachinman.com>",
|
|
6
6
|
"funding": {
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"types": "dist/types/types.d.ts",
|
|
13
13
|
"license": "MIT",
|
|
14
14
|
"engines": {
|
|
15
|
-
"node": ">=
|
|
15
|
+
"node": ">=12"
|
|
16
16
|
},
|
|
17
17
|
"description": "The easiest way to translate your NextJs apps.",
|
|
18
18
|
"keywords": [
|
|
@@ -73,7 +73,8 @@
|
|
|
73
73
|
"@babel/preset-react": "^7.10.4",
|
|
74
74
|
"@babel/preset-typescript": "^7.10.4",
|
|
75
75
|
"@testing-library/react": "^11.2.5",
|
|
76
|
-
"@types/
|
|
76
|
+
"@types/i18next-fs-backend": "^1.1.2",
|
|
77
|
+
"@types/jest": "^27.0.1",
|
|
77
78
|
"@types/node": "^16.7.1",
|
|
78
79
|
"@types/react": "^17.0.3",
|
|
79
80
|
"@types/react-dom": "^17.0.3",
|
|
@@ -104,15 +105,17 @@
|
|
|
104
105
|
"dependencies": {
|
|
105
106
|
"@babel/runtime": "^7.13.17",
|
|
106
107
|
"@types/hoist-non-react-statics": "^3.3.1",
|
|
107
|
-
"@types/i18next-fs-backend": "^1.0.0",
|
|
108
108
|
"core-js": "^3",
|
|
109
109
|
"hoist-non-react-statics": "^3.2.0",
|
|
110
|
-
"i18next": "^
|
|
110
|
+
"i18next": "^21.4.1",
|
|
111
111
|
"i18next-fs-backend": "^1.0.7",
|
|
112
112
|
"react-i18next": "^11.8.13"
|
|
113
113
|
},
|
|
114
114
|
"peerDependencies": {
|
|
115
115
|
"next": ">= 10.0.0",
|
|
116
116
|
"react": ">= 16.8.0"
|
|
117
|
+
},
|
|
118
|
+
"resolutions": {
|
|
119
|
+
"i18next-fs-backend": ">=1.1.4"
|
|
117
120
|
}
|
|
118
121
|
}
|