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 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 _nextI18Next = props.pageProps._nextI18Next;
90
- var locale = props.router.locale; // Memoize the instance and only re-initialize when either:
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 (!locale || !_nextI18Next) return null;
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');
@@ -36,7 +36,7 @@ var defaultConfig = {
36
36
  localePath: LOCALE_PATH,
37
37
  localeStructure: LOCALE_STRUCTURE,
38
38
  react: {
39
- useSuspense: true
39
+ useSuspense: false
40
40
  },
41
41
  reloadOnPrerender: false,
42
42
  serializeConfig: true,
@@ -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
- const {
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 (!locale || !_nextI18Next) return null;
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');
@@ -26,7 +26,7 @@ export const defaultConfig = {
26
26
  localePath: LOCALE_PATH,
27
27
  localeStructure: LOCALE_STRUCTURE,
28
28
  react: {
29
- useSuspense: true
29
+ useSuspense: false
30
30
  },
31
31
  reloadOnPrerender: false,
32
32
  serializeConfig: true,
@@ -89,6 +89,7 @@ export const serverSideTranslations = async (initialLocale, namespacesRequired =
89
89
  return {
90
90
  _nextI18Next: {
91
91
  initialI18nStore,
92
+ initialLocale,
92
93
  userConfig: config.serializeConfig ? userConfig : null
93
94
  }
94
95
  };
@@ -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 _nextI18Next = props.pageProps._nextI18Next;
21
- var locale = props.router.locale; // Memoize the instance and only re-initialize when either:
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 (!locale || !_nextI18Next) return null;
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');
@@ -28,7 +28,7 @@ export var defaultConfig = {
28
28
  localePath: LOCALE_PATH,
29
29
  localeStructure: LOCALE_STRUCTURE,
30
30
  react: {
31
- useSuspense: true
31
+ useSuspense: false
32
32
  },
33
33
  reloadOnPrerender: false,
34
34
  serializeConfig: true,
@@ -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<AppProps> | React.ElementType<AppProps>, configOverride?: UserConfig | null) => ((props: AppProps) => JSX.Element) & hoistNonReactStatics.NonReactStatics<React.ComponentClass<AppProps, any> | React.FunctionComponent<AppProps>, {}>;
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>, {}>;
@@ -36,6 +36,7 @@ export declare type CreateClientReturn = {
36
36
  export declare type SSRConfig = {
37
37
  _nextI18Next: {
38
38
  initialI18nStore: any;
39
+ initialLocale: string;
39
40
  userConfig: UserConfig | null;
40
41
  };
41
42
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-i18next",
3
- "version": "8.10.0",
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": ">=10"
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": "^20.1.0",
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
  }