next-i18next 15.1.2 → 15.3.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
@@ -332,7 +332,7 @@ This option will reload your translations whenever `serverSideTranslations` is c
332
332
  | Key | Default value | Note |
333
333
  | ------------------- | -------------------- | -------------------------------------------------------------- |
334
334
  | `defaultNS` | `'common'` | |
335
- | `localePath` | `'./public/locales'` | Can be a function, see note below. |
335
+ | `localePath` | `'./public/locales'` | Can be a function, see note below. (can also be null, if passing resources option directly via config, like [here](https://www.i18next.com/how-to/add-or-load-translations#add-on-init)) |
336
336
  | `localeExtension` | `'json'` | Ignored if `localePath` is a function. |
337
337
  | `localeStructure` | `'{{lng}}/{{ns}}'` | Ignored if `localePath` is a function. |
338
338
  | `reloadOnPrerender` | `false` | |
@@ -345,6 +345,8 @@ This option will reload your translations whenever `serverSideTranslations` is c
345
345
  If the localePath is a function, make sure you also define the ns option, because on server side we're not able to preload the namespaces then.
346
346
 
347
347
  All other [i18next options](https://www.i18next.com/overview/configuration-options) and [react-i18next options](https://react.i18next.com/latest/i18next-instance) can be passed in as well.
348
+ </br>
349
+ You can also pass in the [`resources`](https://www.i18next.com/overview/configuration-options#languages-namespaces-resources) directly in combination with setting `localePath` to `null`.
348
350
 
349
351
  #### Custom interpolation prefix/suffix
350
352
 
@@ -398,6 +400,20 @@ This means that the i18n configuration file will be in the same directory as `ne
398
400
 
399
401
  **Notice** If your config `next-i18next.config.js` is not in the same directory as `next.config.js`, you must copy it manually (or by custom script).
400
402
 
403
+ #### Adding next-i18next incrementally
404
+
405
+ If you are planning on incrementally add next-i18next to you project we recommended that you will pass your `next-i18next.config` to `appWithTranslation` to avoid any issues.
406
+
407
+ i.e
408
+
409
+ ```js
410
+ import nextI18nextConfig from '../../next-i18next.config';
411
+ //...
412
+ export default appWithTranslation(MyApp, nextI18nextConfig);
413
+ ```
414
+
415
+ See Issue [#2259](https://github.com/i18next/next-i18next/issues/2259) for more information.
416
+
401
417
  ## Notes
402
418
 
403
419
  ### Vercel and Netlify
@@ -102,11 +102,13 @@ var appWithTranslation = exports.appWithTranslation = function appWithTranslatio
102
102
  if (instance) {
103
103
  addResourcesToI18next(instance, resources);
104
104
  } else {
105
- instance = (0, _createClient["default"])(_objectSpread(_objectSpread({}, (0, _createConfig.createConfig)(_objectSpread(_objectSpread({}, userConfig), {}, {
105
+ instance = (0, _createClient["default"])(_objectSpread(_objectSpread(_objectSpread({}, (0, _createConfig.createConfig)(_objectSpread(_objectSpread({}, userConfig), {}, {
106
106
  lng: locale
107
107
  }))), {}, {
108
- lng: locale,
109
- ns: ns,
108
+ lng: locale
109
+ }, ns && {
110
+ ns: ns
111
+ }), {}, {
110
112
  resources: resources
111
113
  })).i18n;
112
114
  addResourcesToI18next(instance, resources);
@@ -1,6 +1,5 @@
1
1
  "use strict";
2
2
 
3
- require("core-js/modules/es.object.keys.js");
4
3
  require("core-js/modules/es.symbol.js");
5
4
  require("core-js/modules/es.object.get-own-property-descriptor.js");
6
5
  require("core-js/modules/web.dom-collections.for-each.js");
@@ -35,6 +34,7 @@ require("core-js/modules/es.regexp.exec.js");
35
34
  require("core-js/modules/es.string.replace.js");
36
35
  require("core-js/modules/es.array.join.js");
37
36
  require("core-js/modules/es.array.map.js");
37
+ require("core-js/modules/es.object.keys.js");
38
38
  require("core-js/modules/es.array.index-of.js");
39
39
  require("core-js/modules/es.array.for-each.js");
40
40
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
@@ -189,7 +189,7 @@ var createConfig = exports.createConfig = function createConfig(userConfig) {
189
189
  return localePath(locale, namespace, false);
190
190
  }
191
191
  };
192
- } else {
192
+ } else if (localePath) {
193
193
  throw new Error("Unsupported localePath type: ".concat((0, _typeof2["default"])(localePath)));
194
194
  }
195
195
 
@@ -217,9 +217,17 @@ var createConfig = exports.createConfig = function createConfig(userConfig) {
217
217
  });
218
218
  return ret;
219
219
  };
220
- var namespacesByLocale = locales.map(function (locale) {
221
- return getLocaleNamespaces(path.resolve(process.cwd(), "".concat(localePath, "/").concat(locale)));
222
- });
220
+ var namespacesByLocale;
221
+ var r = combinedConfig.resources;
222
+ if (!localePath && r) {
223
+ namespacesByLocale = locales.map(function (locale) {
224
+ return Object.keys(r[locale]);
225
+ });
226
+ } else {
227
+ namespacesByLocale = locales.map(function (locale) {
228
+ return getLocaleNamespaces(path.resolve(process.cwd(), "".concat(localePath, "/").concat(locale)));
229
+ });
230
+ }
223
231
  var allNamespaces = [];
224
232
  var _iterator = _createForOfIteratorHelper(namespacesByLocale),
225
233
  _step;
@@ -19,7 +19,7 @@ var defaultConfig = exports.defaultConfig = {
19
19
  locales: LOCALES
20
20
  },
21
21
  get initImmediate() {
22
- return process.browser && typeof window !== 'undefined';
22
+ return typeof window !== 'undefined';
23
23
  },
24
24
  interpolation: {
25
25
  escapeValue: false
@@ -59,7 +59,9 @@ export const appWithTranslation = (WrappedComponent, configOverride = null) => {
59
59
  lng: locale
60
60
  }),
61
61
  lng: locale,
62
- ns,
62
+ ...(ns && {
63
+ ns
64
+ }),
63
65
  resources
64
66
  }).i18n;
65
67
  addResourcesToI18next(instance, resources);
@@ -130,7 +130,7 @@ export const createConfig = userConfig => {
130
130
  addPath: (locale, namespace) => localePath(locale, namespace, true),
131
131
  loadPath: (locale, namespace) => localePath(locale, namespace, false)
132
132
  };
133
- } else {
133
+ } else if (localePath) {
134
134
  throw new Error(`Unsupported localePath type: ${typeof localePath}`);
135
135
  }
136
136
 
@@ -156,7 +156,13 @@ export const createConfig = userConfig => {
156
156
  });
157
157
  return ret;
158
158
  };
159
- const namespacesByLocale = locales.map(locale => getLocaleNamespaces(path.resolve(process.cwd(), `${localePath}/${locale}`)));
159
+ let namespacesByLocale;
160
+ const r = combinedConfig.resources;
161
+ if (!localePath && r) {
162
+ namespacesByLocale = locales.map(locale => Object.keys(r[locale]));
163
+ } else {
164
+ namespacesByLocale = locales.map(locale => getLocaleNamespaces(path.resolve(process.cwd(), `${localePath}/${locale}`)));
165
+ }
160
166
  const allNamespaces = [];
161
167
  for (const localNamespaces of namespacesByLocale) {
162
168
  allNamespaces.push(...localNamespaces);
@@ -12,7 +12,7 @@ export const defaultConfig = {
12
12
  locales: LOCALES
13
13
  },
14
14
  get initImmediate() {
15
- return process.browser && typeof window !== 'undefined';
15
+ return typeof window !== 'undefined';
16
16
  },
17
17
  interpolation: {
18
18
  escapeValue: false
@@ -61,11 +61,13 @@ export var appWithTranslation = function appWithTranslation(WrappedComponent) {
61
61
  if (instance) {
62
62
  addResourcesToI18next(instance, resources);
63
63
  } else {
64
- instance = createClient(_objectSpread(_objectSpread({}, createConfig(_objectSpread(_objectSpread({}, userConfig), {}, {
64
+ instance = createClient(_objectSpread(_objectSpread(_objectSpread({}, createConfig(_objectSpread(_objectSpread({}, userConfig), {}, {
65
65
  lng: locale
66
66
  }))), {}, {
67
- lng: locale,
68
- ns: ns,
67
+ lng: locale
68
+ }, ns && {
69
+ ns: ns
70
+ }), {}, {
69
71
  resources: resources
70
72
  })).i18n;
71
73
  addResourcesToI18next(instance, resources);
@@ -150,7 +150,7 @@ export var createConfig = function createConfig(userConfig) {
150
150
  return localePath(locale, namespace, false);
151
151
  }
152
152
  };
153
- } else {
153
+ } else if (localePath) {
154
154
  throw new Error("Unsupported localePath type: ".concat(_typeof(localePath)));
155
155
  }
156
156
 
@@ -178,9 +178,17 @@ export var createConfig = function createConfig(userConfig) {
178
178
  });
179
179
  return ret;
180
180
  };
181
- var namespacesByLocale = locales.map(function (locale) {
182
- return getLocaleNamespaces(path.resolve(process.cwd(), "".concat(localePath, "/").concat(locale)));
183
- });
181
+ var namespacesByLocale;
182
+ var r = combinedConfig.resources;
183
+ if (!localePath && r) {
184
+ namespacesByLocale = locales.map(function (locale) {
185
+ return Object.keys(r[locale]);
186
+ });
187
+ } else {
188
+ namespacesByLocale = locales.map(function (locale) {
189
+ return getLocaleNamespaces(path.resolve(process.cwd(), "".concat(localePath, "/").concat(locale)));
190
+ });
191
+ }
184
192
  var allNamespaces = [];
185
193
  var _iterator = _createForOfIteratorHelper(namespacesByLocale),
186
194
  _step;
@@ -12,7 +12,7 @@ export var defaultConfig = {
12
12
  locales: LOCALES
13
13
  },
14
14
  get initImmediate() {
15
- return process.browser && typeof window !== 'undefined';
15
+ return typeof window !== 'undefined';
16
16
  },
17
17
  interpolation: {
18
18
  escapeValue: false
@@ -20,7 +20,7 @@ type DefaultNamespace = TypeOptions['defaultNS'];
20
20
  export type UserConfig = {
21
21
  i18n: NextJsI18NConfig;
22
22
  localeExtension?: string;
23
- localePath?: string | ((locale: string, namespace: string, missing: boolean) => string);
23
+ localePath?: string | ((locale: string, namespace: string, missing: boolean) => string) | null;
24
24
  localeStructure?: string;
25
25
  onPreInitI18next?: (i18n: I18n) => void;
26
26
  reloadOnPrerender?: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-i18next",
3
- "version": "15.1.2",
3
+ "version": "15.3.0",
4
4
  "repository": "git@github.com:i18next/next-i18next.git",
5
5
  "author": "i18next",
6
6
  "funding": [
@@ -47,6 +47,7 @@
47
47
  "build:examples": "npm-run-all -s build:example:*",
48
48
  "build:example:simple": "cd examples/simple && npm run build",
49
49
  "build:example:ssg": "cd examples/ssg && npm run build",
50
+ "build:example:auto-static-optimize": "cd examples/auto-static-optimize && npm run build",
50
51
  "typecheck": "tsc --project ./tsconfig.json --noEmit",
51
52
  "typecheck:example:simple": "cd examples/simple && npm run typecheck",
52
53
  "check-size": "size-limit",
@@ -58,8 +59,9 @@
58
59
  "install:examples": "npm-run-all -s install:example:*",
59
60
  "install:example:simple": "cd examples/simple && npm install",
60
61
  "install:example:ssg": "cd examples/ssg && npm install",
62
+ "install:example:auto-static-optimize": "cd examples/auto-static-optimize && npm install",
61
63
  "move-build-to-examples?": "Hack: see # @link https://github.com/i18next/next-i18next/pull/2012",
62
- "move-build-to-examples": "rimraf ./examples/*/node_modules/next-i18next && cpy './package.json' './*.js' './*.ts' './dist' ./examples/simple/node_modules/next-i18next && cpy './package.json' './*.js' './*.ts' './dist' ./examples/ssg/node_modules/next-i18next",
64
+ "move-build-to-examples": "rimraf ./examples/*/node_modules/next-i18next && cpy './package.json' './*.js' './*.ts' './dist' ./examples/simple/node_modules/next-i18next && cpy './package.json' './*.js' './*.ts' './dist' ./examples/ssg/node_modules/next-i18next && cpy './package.json' './*.js' './*.ts' './dist' ./examples/auto-static-optimize/node_modules/next-i18next ",
63
65
  "test:e2e": "start-server-and-test 'cd examples/simple && npm run start' http://127.0.0.1:3000 cy:run",
64
66
  "cy:run": "cypress run",
65
67
  "example": "npm run example:simple",
@@ -114,7 +116,7 @@
114
116
  "eslint-plugin-typescript-sort-keys": "^3.1.0",
115
117
  "gh-release": "7.0.2",
116
118
  "husky": "^8.0.3",
117
- "i18next": "^23.7.13",
119
+ "i18next": "^23.7.16",
118
120
  "jest": "^29.7.0",
119
121
  "jest-environment-jsdom": "^29.7.0",
120
122
  "next": "^14.0.1",