next-i18next 13.0.3 → 13.1.1

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
@@ -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,
@@ -89,7 +90,7 @@ var serverSideTranslations = /*#__PURE__*/function () {
89
90
  _context.next = 12;
90
91
  break;
91
92
  }
92
- throw new Error('next-i18next was unable to find a user config');
93
+ throw new Error("next-i18next was unable to find a user config at ".concat(_path["default"].resolve(DEFAULT_CONFIG_PATH)));
93
94
  case 12:
94
95
  config = (0, _createConfig.createConfig)(_objectSpread(_objectSpread({}, userConfig), {}, {
95
96
  lng: initialLocale
@@ -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');
@@ -14,7 +16,7 @@ export const serverSideTranslations = async (initialLocale, namespacesRequired =
14
16
  userConfig = await import(path.resolve(DEFAULT_CONFIG_PATH));
15
17
  }
16
18
  if (userConfig === null) {
17
- throw new Error('next-i18next was unable to find a user config');
19
+ throw new Error(`next-i18next was unable to find a user config at ${path.resolve(DEFAULT_CONFIG_PATH)}`);
18
20
  }
19
21
  const config = createConfig({
20
22
  ...userConfig,
@@ -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,
@@ -55,7 +56,7 @@ export var serverSideTranslations = /*#__PURE__*/function () {
55
56
  _context.next = 12;
56
57
  break;
57
58
  }
58
- throw new Error('next-i18next was unable to find a user config');
59
+ throw new Error("next-i18next was unable to find a user config at ".concat(path.resolve(DEFAULT_CONFIG_PATH)));
59
60
  case 12:
60
61
  config = createConfig(_objectSpread(_objectSpread({}, userConfig), {}, {
61
62
  lng: initialLocale
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-i18next",
3
- "version": "13.0.3",
3
+ "version": "13.1.1",
4
4
  "repository": "git@github.com:i18next/next-i18next.git",
5
5
  "author": "i18next",
6
6
  "funding": [