next-i18next 8.10.0 → 9.2.0
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 +16 -0
- package/dist/commonjs/appWithTranslation.js +7 -4
- package/dist/commonjs/config/defaultConfig.js +1 -1
- package/dist/commonjs/serverSideTranslations.js +1 -0
- package/dist/es/appWithTranslation.js +5 -5
- package/dist/es/config/defaultConfig.js +1 -1
- package/dist/es/serverSideTranslations.js +1 -0
- package/dist/esm/appWithTranslation.js +7 -4
- package/dist/esm/config/defaultConfig.js +1 -1
- 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 +6 -3
package/README.md
CHANGED
|
@@ -260,6 +260,8 @@ To migrate from previous versions to the version 8, check out the [v8-migration
|
|
|
260
260
|
|
|
261
261
|
## Notes
|
|
262
262
|
|
|
263
|
+
### Docker
|
|
264
|
+
|
|
263
265
|
For Docker deployment, note that if you use the `Dockerfile` from [Next.js docs](https://nextjs.org/docs/deployment#docker-image) do not forget to copy `next.config.js` and `next-i18next.config.js` into the Docker image.
|
|
264
266
|
|
|
265
267
|
```
|
|
@@ -267,6 +269,20 @@ COPY --from=builder /app/next.config.js ./next.config.js
|
|
|
267
269
|
COPY --from=builder /app/next-i18next.config.js ./next-i18next.config.js
|
|
268
270
|
```
|
|
269
271
|
|
|
272
|
+
### Asynchronous i18next backends
|
|
273
|
+
|
|
274
|
+
If you choose to use an i18next backend different to the built-in [i18next-fs-backend](https://github.com/i18next/i18next-fs-backend), you will need to ensure the translation resources are loaded before you call the `t` function.
|
|
275
|
+
Since [React suspense is not yet supported for SSR](https://github.com/isaachinman/next-i18next/issues/1255), this can be solved in 2 different ways:
|
|
276
|
+
|
|
277
|
+
**1) Preload the namespaces:**
|
|
278
|
+
|
|
279
|
+
Set the `ns` option, like in [this example](https://github.com/locize/next-i18next-locize/blob/main/next-i18next.config.js#L17). Doing this will ensure all translation resources are loaded on initialization.
|
|
280
|
+
|
|
281
|
+
**2) Check the ready flag:**
|
|
282
|
+
|
|
283
|
+
If you cannot or do not want to provide the `ns` array, calls to the `t` function will cause namespaces to be loaded on the fly. This means you'll need to handle the "not ready" state by checking `ready === true` or `props.tReady === true`. Not doing so will result in rendering your translations before they loaded, which will cause "save missing" be called despite the translations actually existing (just yet not loaded).
|
|
284
|
+
This can be done with the [useTranslation hook](https://react.i18next.com/latest/usetranslation-hook#not-using-suspense) or the [withTranslation HOC](https://react.i18next.com/latest/withtranslation-hoc#not-using-suspense).
|
|
285
|
+
|
|
270
286
|
## Contributors
|
|
271
287
|
|
|
272
288
|
Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds/all-contributors#emoji-key)):
|
|
@@ -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.2.0",
|
|
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": [
|
|
@@ -107,12 +107,15 @@
|
|
|
107
107
|
"@types/hoist-non-react-statics": "^3.3.1",
|
|
108
108
|
"core-js": "^3",
|
|
109
109
|
"hoist-non-react-statics": "^3.2.0",
|
|
110
|
-
"i18next": "^
|
|
110
|
+
"i18next": "^21.5.3",
|
|
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
|
}
|