next-i18next 10.2.0 → 10.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
@@ -254,6 +254,27 @@ const Component = () => {
254
254
  }
255
255
  ```
256
256
 
257
+ #### Custom interpolation prefix/suffix
258
+
259
+ By default, i18next uses `{{` as prefix and `}}` as suffix for [interpolation](https://www.i18next.com/translation-function/interpolation).
260
+ If you want/need to override these interpolation settings, you **must** also specify an alternative `localeStructure` setting that matches your custom prefix and suffix.
261
+
262
+ For example, if you want to use `{` and `}` the config would look like this:
263
+
264
+ ```js
265
+ {
266
+ i18n: {
267
+ defaultLocale: 'en',
268
+ locales: ['en', 'nl'],
269
+ },
270
+ interpolation: {
271
+ prefix: '{',
272
+ suffix: '}',
273
+ },
274
+ localeStructure: '{lng}/{ns}',
275
+ }
276
+ ```
277
+
257
278
  ## Migration to v8
258
279
 
259
280
  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,9 +86,11 @@ 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$initialL;
90
+
89
91
  var _ref = props.pageProps,
90
92
  _nextI18Next = _ref._nextI18Next;
91
- var locale = null; // Memoize the instance and only re-initialize when either:
93
+ var locale = (_nextI18Next$initialL = _nextI18Next === null || _nextI18Next === void 0 ? void 0 : _nextI18Next.initialLocale) !== null && _nextI18Next$initialL !== void 0 ? _nextI18Next$initialL : null; // Memoize the instance and only re-initialize when either:
92
94
  // 1. The route changes (non-shallowly)
93
95
  // 2. Router locale changes
94
96
 
@@ -97,9 +99,7 @@ var appWithTranslation = function appWithTranslation(WrappedComponent) {
97
99
 
98
100
  if (!_nextI18Next) return null;
99
101
  var userConfig = _nextI18Next.userConfig;
100
- var initialI18nStore = _nextI18Next.initialI18nStore,
101
- initialLocale = _nextI18Next.initialLocale;
102
- locale = initialLocale;
102
+ var initialI18nStore = _nextI18Next.initialI18nStore;
103
103
 
104
104
  if (userConfig === null && configOverride === null) {
105
105
  throw new Error('appWithTranslation was called without a next-i18next config');
@@ -75,6 +75,9 @@ var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/h
75
75
 
76
76
  var _defaultConfig = require("./defaultConfig");
77
77
 
78
+ var _excluded = ["i18n"],
79
+ _excluded2 = ["i18n"];
80
+
78
81
  function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
79
82
 
80
83
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
@@ -98,9 +101,9 @@ var createConfig = function createConfig(userConfig) {
98
101
 
99
102
 
100
103
  var userI18n = userConfig.i18n,
101
- userConfigStripped = (0, _objectWithoutProperties2["default"])(userConfig, ["i18n"]);
104
+ userConfigStripped = (0, _objectWithoutProperties2["default"])(userConfig, _excluded);
102
105
  var defaultI18n = _defaultConfig.defaultConfig.i18n,
103
- defaultConfigStripped = (0, _objectWithoutProperties2["default"])(_defaultConfig.defaultConfig, ["i18n"]);
106
+ defaultConfigStripped = (0, _objectWithoutProperties2["default"])(_defaultConfig.defaultConfig, _excluded2);
104
107
 
105
108
  var combinedConfig = _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, defaultConfigStripped), userConfigStripped), defaultI18n), userI18n);
106
109
 
@@ -12,20 +12,20 @@ export const appWithTranslation = (WrappedComponent, configOverride = null) => {
12
12
  const {
13
13
  _nextI18Next
14
14
  } = props.pageProps;
15
- let locale = null; // Memoize the instance and only re-initialize when either:
15
+ const locale = (_nextI18Next === null || _nextI18Next === void 0 ? void 0 : _nextI18Next.initialLocale) ?? null; // Memoize the instance and only re-initialize when either:
16
16
  // 1. The route changes (non-shallowly)
17
17
  // 2. Router locale changes
18
18
 
19
19
  const i18n = useMemo(() => {
20
+ var _userConfig;
21
+
20
22
  if (!_nextI18Next) return null;
21
23
  let {
22
24
  userConfig
23
25
  } = _nextI18Next;
24
26
  const {
25
- initialI18nStore,
26
- initialLocale
27
+ initialI18nStore
27
28
  } = _nextI18Next;
28
- locale = initialLocale;
29
29
 
30
30
  if (userConfig === null && configOverride === null) {
31
31
  throw new Error('appWithTranslation was called without a next-i18next config');
@@ -35,7 +35,7 @@ export const appWithTranslation = (WrappedComponent, configOverride = null) => {
35
35
  userConfig = configOverride;
36
36
  }
37
37
 
38
- if (!userConfig?.i18n) {
38
+ if (!((_userConfig = userConfig) !== null && _userConfig !== void 0 && _userConfig.i18n)) {
39
39
  throw new Error('appWithTranslation was called without config.i18n');
40
40
  }
41
41
 
@@ -1,7 +1,9 @@
1
1
  import { defaultConfig } from './defaultConfig';
2
2
  const deepMergeObjects = ['backend', 'detection'];
3
3
  export const createConfig = userConfig => {
4
- if (typeof userConfig?.lng !== 'string') {
4
+ var _userConfig$use;
5
+
6
+ if (typeof (userConfig === null || userConfig === void 0 ? void 0 : userConfig.lng) !== 'string') {
5
7
  throw new Error('config.lng was not passed into createConfig');
6
8
  } //
7
9
  // Initial merge of default and user-provided config
@@ -42,7 +44,7 @@ export const createConfig = userConfig => {
42
44
  combinedConfig.fallbackLng = combinedConfig.defaultLocale;
43
45
  }
44
46
 
45
- const hasCustomBackend = userConfig?.use?.some(b => b.type === 'backend');
47
+ const hasCustomBackend = userConfig === null || userConfig === void 0 ? void 0 : (_userConfig$use = userConfig.use) === null || _userConfig$use === void 0 ? void 0 : _userConfig$use.some(b => b.type === 'backend');
46
48
 
47
49
  if (!process.browser && typeof window === 'undefined') {
48
50
  combinedConfig.preload = locales;
@@ -58,8 +60,10 @@ export const createConfig = userConfig => {
58
60
  //
59
61
 
60
62
  if (typeof defaultNS === 'string' && typeof lng !== 'undefined') {
61
- const prefix = userConfig?.interpolation?.prefix ?? '{{';
62
- const suffix = userConfig?.interpolation?.suffix ?? '}}';
63
+ var _userConfig$interpola, _userConfig$interpola2;
64
+
65
+ const prefix = (userConfig === null || userConfig === void 0 ? void 0 : (_userConfig$interpola = userConfig.interpolation) === null || _userConfig$interpola === void 0 ? void 0 : _userConfig$interpola.prefix) ?? '{{';
66
+ const suffix = (userConfig === null || userConfig === void 0 ? void 0 : (_userConfig$interpola2 = userConfig.interpolation) === null || _userConfig$interpola2 === void 0 ? void 0 : _userConfig$interpola2.suffix) ?? '}}';
63
67
  const defaultLocaleStructure = localeStructure.replace(`${prefix}lng${suffix}`, lng).replace(`${prefix}ns${suffix}`, defaultNS);
64
68
  const defaultFile = `/${defaultLocaleStructure}.${localeExtension}`;
65
69
  const defaultNSPath = path.join(localePath, defaultFile);
@@ -4,7 +4,9 @@ export default (config => {
4
4
  let initPromise;
5
5
 
6
6
  if (!instance.isInitialized) {
7
- config?.use?.forEach(x => instance.use(x));
7
+ var _config$use;
8
+
9
+ config === null || config === void 0 ? void 0 : (_config$use = config.use) === null || _config$use === void 0 ? void 0 : _config$use.forEach(x => instance.use(x));
8
10
  initPromise = instance.init(config);
9
11
  } else {
10
12
  initPromise = Promise.resolve(i18n.t);
@@ -16,13 +16,15 @@ export default (config => {
16
16
  let initPromise;
17
17
 
18
18
  if (!instance.isInitialized) {
19
- const hasCustomBackend = config?.use?.some(b => b.type === 'backend');
19
+ var _config$use, _config$use2;
20
+
21
+ const hasCustomBackend = config === null || config === void 0 ? void 0 : (_config$use = config.use) === null || _config$use === void 0 ? void 0 : _config$use.some(b => b.type === 'backend');
20
22
 
21
23
  if (!hasCustomBackend) {
22
24
  instance.use(i18nextFSBackend);
23
25
  }
24
26
 
25
- config?.use?.forEach(x => instance.use(x));
27
+ config === null || config === void 0 ? void 0 : (_config$use2 = config.use) === null || _config$use2 === void 0 ? void 0 : _config$use2.forEach(x => instance.use(x));
26
28
  initPromise = instance.init(config);
27
29
  } else {
28
30
  initPromise = Promise.resolve(i18n.t);
@@ -57,7 +57,7 @@ export const serverSideTranslations = async (initialLocale, namespacesRequired =
57
57
  } = config;
58
58
 
59
59
  if (reloadOnPrerender) {
60
- await globalI18n?.reloadResources();
60
+ await (globalI18n === null || globalI18n === void 0 ? void 0 : globalI18n.reloadResources());
61
61
  }
62
62
 
63
63
  const {
@@ -17,9 +17,11 @@ 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$initialL;
21
+
20
22
  var _ref = props.pageProps,
21
23
  _nextI18Next = _ref._nextI18Next;
22
- var locale = null; // Memoize the instance and only re-initialize when either:
24
+ var locale = (_nextI18Next$initialL = _nextI18Next === null || _nextI18Next === void 0 ? void 0 : _nextI18Next.initialLocale) !== null && _nextI18Next$initialL !== void 0 ? _nextI18Next$initialL : null; // Memoize the instance and only re-initialize when either:
23
25
  // 1. The route changes (non-shallowly)
24
26
  // 2. Router locale changes
25
27
 
@@ -28,9 +30,7 @@ export var appWithTranslation = function appWithTranslation(WrappedComponent) {
28
30
 
29
31
  if (!_nextI18Next) return null;
30
32
  var userConfig = _nextI18Next.userConfig;
31
- var initialI18nStore = _nextI18Next.initialI18nStore,
32
- initialLocale = _nextI18Next.initialLocale;
33
- locale = initialLocale;
33
+ var initialI18nStore = _nextI18Next.initialI18nStore;
34
34
 
35
35
  if (userConfig === null && configOverride === null) {
36
36
  throw new Error('appWithTranslation was called without a next-i18next config');
@@ -2,6 +2,8 @@ import _typeof from "@babel/runtime/helpers/typeof";
2
2
  import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
3
3
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
4
4
  import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
5
+ var _excluded = ["i18n"],
6
+ _excluded2 = ["i18n"];
5
7
 
6
8
  function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
7
9
 
@@ -26,10 +28,10 @@ export var createConfig = function createConfig(userConfig) {
26
28
 
27
29
 
28
30
  var userI18n = userConfig.i18n,
29
- userConfigStripped = _objectWithoutProperties(userConfig, ["i18n"]);
31
+ userConfigStripped = _objectWithoutProperties(userConfig, _excluded);
30
32
 
31
33
  var defaultI18n = defaultConfig.i18n,
32
- defaultConfigStripped = _objectWithoutProperties(defaultConfig, ["i18n"]);
34
+ defaultConfigStripped = _objectWithoutProperties(defaultConfig, _excluded2);
33
35
 
34
36
  var combinedConfig = _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, defaultConfigStripped), userConfigStripped), defaultI18n), userI18n);
35
37
 
@@ -1,8 +1,8 @@
1
- import _regeneratorRuntime from "@babel/runtime/regenerator";
2
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
2
  import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
4
3
  import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
5
4
  import _typeof from "@babel/runtime/helpers/typeof";
5
+ import _regeneratorRuntime from "@babel/runtime/regenerator";
6
6
 
7
7
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
8
8
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-i18next",
3
- "version": "10.2.0",
3
+ "version": "10.3.0",
4
4
  "repository": "git@github.com:isaachinman/next-i18next.git",
5
5
  "author": "Isaac Hinman <isaac@isaachinman.com>",
6
6
  "funding": {
@@ -96,7 +96,7 @@
96
96
  "eslint-plugin-typescript-sort-keys": "^2.1.0",
97
97
  "husky": "^3.0.0",
98
98
  "jest": "^26.6.3",
99
- "next": "^10.0.4",
99
+ "next": "^11.1.3",
100
100
  "react": "^17.0.1",
101
101
  "react-dom": "^17.0.1",
102
102
  "start-server-and-test": "^1.12.0",