next-i18next 13.0.2 → 13.1.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
@@ -140,7 +140,9 @@ The `serverSideTranslations` HOC is primarily responsible for passing translatio
140
140
 
141
141
  ### useTranslation
142
142
 
143
- This is the hook which you'll actually use to do the translation itself. The `useTranslation` hook [comes from `react-i18next`](https://react.i18next.com/latest/usetranslation-hook), but can be imported from `next-i18next` directly:
143
+ This is the hook which you'll actually use to do the translation itself. The `useTranslation` hook [comes from `react-i18next`](https://react.i18next.com/latest/usetranslation-hook), but needs to be imported from `next-i18next` directly.
144
+ <br/>
145
+ **Do NOT use the `useTranslation` export of `react-i18next`, but ONLY use the on of `next-i18next`!**
144
146
 
145
147
  ```tsx
146
148
  import { useTranslation } from 'next-i18next'
@@ -327,6 +329,34 @@ For example, if you want to use `{` and `}` the config would look like this:
327
329
  }
328
330
  ```
329
331
 
332
+ #### Custom `next-i18next.config.js` path
333
+
334
+ If you want to change the default config path, you can set the environment variable `I18NEXT_DEFAULT_CONFIG_PATH`.
335
+
336
+ For example, inside the `.env` file you can set a static path:
337
+ ```
338
+ I18NEXT_DEFAULT_CONFIG_PATH=/path/to/project/apps/my-app/next-i18next.config.js
339
+ ```
340
+
341
+ Or you can use a trick for dynamic path and set the following inside `next.config.js`:
342
+
343
+ ```js
344
+ process.env.I18NEXT_DEFAULT_CONFIG_PATH = `${__dirname}/next-i18next.config.js`;
345
+
346
+ // ... Some other imports
347
+
348
+ const { i18n } = require('./next-i18next.config');
349
+
350
+ // ... Some other code
351
+
352
+ module.exports = {
353
+ i18n,
354
+ ...
355
+ };
356
+ ```
357
+
358
+ This means that the i18n configuration file will be in the same directory as `next.config.js` and it doesn't matter where your current working directory is. This helps for example for `nx` when you have monorepo and start your application from project root but the application is in `apps/{appName}`.
359
+
330
360
  ## Notes
331
361
 
332
362
  ### Vercel and Netlify
@@ -33,6 +33,7 @@ require("core-js/modules/es.regexp.exec.js");
33
33
  require("core-js/modules/es.string.replace.js");
34
34
  require("core-js/modules/es.array.join.js");
35
35
  require("core-js/modules/es.array.map.js");
36
+ require("core-js/modules/es.array.index-of.js");
36
37
  require("core-js/modules/es.array.for-each.js");
37
38
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
38
39
  var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
@@ -190,6 +191,7 @@ var createConfig = function createConfig(userConfig) {
190
191
  // Set server side preload (namespaces)
191
192
  //
192
193
  if (!combinedConfig.ns && typeof lng !== 'undefined') {
194
+ var _userConfig$interpola5, _userConfig$interpola6, _userConfig$interpola7, _userConfig$interpola8;
193
195
  if (typeof localePath === 'function') {
194
196
  throw new Error('Must provide all namespaces in ns option if using a function as localePath');
195
197
  }
@@ -228,6 +230,11 @@ var createConfig = function createConfig(userConfig) {
228
230
  }
229
231
  return (0, _utils.unique)(allNamespaces);
230
232
  };
233
+ var _prefix = (_userConfig$interpola5 = userConfig === null || userConfig === void 0 ? void 0 : (_userConfig$interpola6 = userConfig.interpolation) === null || _userConfig$interpola6 === void 0 ? void 0 : _userConfig$interpola6.prefix) !== null && _userConfig$interpola5 !== void 0 ? _userConfig$interpola5 : '{{';
234
+ var _suffix = (_userConfig$interpola7 = userConfig === null || userConfig === void 0 ? void 0 : (_userConfig$interpola8 = userConfig.interpolation) === null || _userConfig$interpola8 === void 0 ? void 0 : _userConfig$interpola8.suffix) !== null && _userConfig$interpola7 !== void 0 ? _userConfig$interpola7 : '}}';
235
+ if (localeStructure.indexOf("".concat(_prefix, "lng").concat(_suffix)) > localeStructure.indexOf("".concat(_prefix, "ns").concat(_suffix))) {
236
+ throw new Error('Must provide all namespaces in ns option if using a localeStructure that is not namespace-listable like lng/ns');
237
+ }
231
238
  combinedConfig.ns = getNamespaces((0, _utils.unique)([lng].concat((0, _toConsumableArray2["default"])((0, _utils.getFallbackForLng)(lng, combinedConfig.fallbackLng)))));
232
239
  }
233
240
  }
@@ -41,7 +41,8 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
41
41
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
42
42
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
43
43
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
44
- var DEFAULT_CONFIG_PATH = './next-i18next.config.js';
44
+ var _process$env$I18NEXT_ = process.env.I18NEXT_DEFAULT_CONFIG_PATH,
45
+ DEFAULT_CONFIG_PATH = _process$env$I18NEXT_ === void 0 ? './next-i18next.config.js' : _process$env$I18NEXT_;
45
46
  var serverSideTranslations = /*#__PURE__*/function () {
46
47
  var _ref = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(initialLocale) {
47
48
  var namespacesRequired,
@@ -158,6 +158,11 @@ export const createConfig = userConfig => {
158
158
  }
159
159
  return unique(allNamespaces);
160
160
  };
161
+ const prefix = userConfig?.interpolation?.prefix ?? '{{';
162
+ const suffix = userConfig?.interpolation?.suffix ?? '}}';
163
+ if (localeStructure.indexOf(`${prefix}lng${suffix}`) > localeStructure.indexOf(`${prefix}ns${suffix}`)) {
164
+ throw new Error('Must provide all namespaces in ns option if using a localeStructure that is not namespace-listable like lng/ns');
165
+ }
161
166
  combinedConfig.ns = getNamespaces(unique([lng, ...getFallbackForLng(lng, combinedConfig.fallbackLng)]));
162
167
  }
163
168
  }
@@ -4,7 +4,9 @@ import { createConfig } from './config/createConfig';
4
4
  import createClient from './createClient/node';
5
5
  import { globalI18n } from './appWithTranslation';
6
6
  import { getFallbackForLng, unique } from './utils';
7
- const DEFAULT_CONFIG_PATH = './next-i18next.config.js';
7
+ const {
8
+ I18NEXT_DEFAULT_CONFIG_PATH: DEFAULT_CONFIG_PATH = './next-i18next.config.js'
9
+ } = process.env;
8
10
  export const serverSideTranslations = async (initialLocale, namespacesRequired = undefined, configOverride = null, extraLocales = false) => {
9
11
  if (typeof initialLocale !== 'string') {
10
12
  throw new Error('Initial locale argument was not passed into serverSideTranslations');
@@ -154,6 +154,7 @@ export var createConfig = function createConfig(userConfig) {
154
154
  // Set server side preload (namespaces)
155
155
  //
156
156
  if (!combinedConfig.ns && typeof lng !== 'undefined') {
157
+ var _userConfig$interpola5, _userConfig$interpola6, _userConfig$interpola7, _userConfig$interpola8;
157
158
  if (typeof localePath === 'function') {
158
159
  throw new Error('Must provide all namespaces in ns option if using a function as localePath');
159
160
  }
@@ -192,6 +193,11 @@ export var createConfig = function createConfig(userConfig) {
192
193
  }
193
194
  return unique(allNamespaces);
194
195
  };
196
+ var _prefix = (_userConfig$interpola5 = userConfig === null || userConfig === void 0 ? void 0 : (_userConfig$interpola6 = userConfig.interpolation) === null || _userConfig$interpola6 === void 0 ? void 0 : _userConfig$interpola6.prefix) !== null && _userConfig$interpola5 !== void 0 ? _userConfig$interpola5 : '{{';
197
+ var _suffix = (_userConfig$interpola7 = userConfig === null || userConfig === void 0 ? void 0 : (_userConfig$interpola8 = userConfig.interpolation) === null || _userConfig$interpola8 === void 0 ? void 0 : _userConfig$interpola8.suffix) !== null && _userConfig$interpola7 !== void 0 ? _userConfig$interpola7 : '}}';
198
+ if (localeStructure.indexOf("".concat(_prefix, "lng").concat(_suffix)) > localeStructure.indexOf("".concat(_prefix, "ns").concat(_suffix))) {
199
+ throw new Error('Must provide all namespaces in ns option if using a localeStructure that is not namespace-listable like lng/ns');
200
+ }
195
201
  combinedConfig.ns = getNamespaces(unique([lng].concat(_toConsumableArray(getFallbackForLng(lng, combinedConfig.fallbackLng)))));
196
202
  }
197
203
  }
@@ -9,7 +9,8 @@ import { createConfig } from './config/createConfig';
9
9
  import createClient from './createClient/node';
10
10
  import { globalI18n } from './appWithTranslation';
11
11
  import { getFallbackForLng, unique } from './utils';
12
- var DEFAULT_CONFIG_PATH = './next-i18next.config.js';
12
+ var _process$env$I18NEXT_ = process.env.I18NEXT_DEFAULT_CONFIG_PATH,
13
+ DEFAULT_CONFIG_PATH = _process$env$I18NEXT_ === void 0 ? './next-i18next.config.js' : _process$env$I18NEXT_;
13
14
  export var serverSideTranslations = /*#__PURE__*/function () {
14
15
  var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(initialLocale) {
15
16
  var namespacesRequired,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-i18next",
3
- "version": "13.0.2",
3
+ "version": "13.1.0",
4
4
  "repository": "git@github.com:i18next/next-i18next.git",
5
5
  "author": "i18next",
6
6
  "funding": [