next-i18next 10.5.0 → 11.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/LICENSE +2 -2
- package/README.md +73 -46
- package/dist/commonjs/appWithTranslation.js +18 -10
- package/dist/commonjs/config/createConfig.js +16 -6
- package/dist/commonjs/config/defaultConfig.js +0 -1
- package/dist/commonjs/index.js +8 -8
- package/dist/commonjs/types.js +18 -18
- package/dist/es/appWithTranslation.js +17 -15
- package/dist/es/config/createConfig.js +8 -11
- package/dist/es/config/defaultConfig.js +0 -1
- package/dist/es/createClient/browser.js +1 -3
- package/dist/es/createClient/node.js +2 -4
- package/dist/es/serverSideTranslations.js +1 -1
- package/dist/esm/appWithTranslation.js +17 -9
- package/dist/esm/config/createConfig.js +12 -3
- package/dist/esm/config/defaultConfig.js +0 -1
- package/dist/types/config/defaultConfig.d.ts +0 -1
- package/dist/types/types.d.ts +0 -1
- package/package.json +77 -56
- package/vercel.json +0 -5
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,28 +1,30 @@
|
|
|
1
1
|
# next-i18next
|
|
2
2
|
|
|
3
|
-
[](https://circleci.com/gh/isaachinman/next-i18next)
|
|
3
|
+
[](https://circleci.com/gh/i18next/next-i18next)
|
|
5
4
|
[](https://packagequality.com/#?package=next-i18next)
|
|
5
|
+
[](https://www.npmjs.com/package/next-i18next)
|
|
6
|
+

|
|
6
7
|
|
|
7
|
-
**The easiest way to translate your
|
|
8
|
+
**The easiest way to translate your Next.js apps.**
|
|
8
9
|
|
|
9
|
-
If you are using next-i18next in production,
|
|
10
|
+
If you are using next-i18next in production and like to unleash some super powers, you may have a look at [this blog post](https://dev.to/adrai/all-side-optimized-nextjs-translations-4n9i).
|
|
11
|
+
[](https://dev.to/adrai/all-side-optimized-nextjs-translations-4n9i)
|
|
10
12
|
|
|
11
13
|
## What is this?
|
|
12
14
|
|
|
13
|
-
Although
|
|
15
|
+
Although Next.js [provides internationalised routing directly](https://nextjs.org/docs/advanced-features/i18n-routing), it does not handle any management of translation content, or the actual translation functionality itself. All Next.js does is keep your locales and URLs in sync.
|
|
14
16
|
|
|
15
17
|
To complement this, `next-i18next` provides the remaining functionality – management of translation content, and components/hooks to translate your React components – while fully supporting SSG/SSR, multiple [namespaces](https://www.i18next.com/principles/namespaces), codesplitting, etc.
|
|
16
18
|
|
|
17
19
|
While `next-i18next` uses [i18next](https://www.i18next.com/) and [react-i18next](https://github.com/i18next/react-i18next) under the hood, users of `next-i18next` simply need to include their translation content as JSON files and don't have to worry about much else.
|
|
18
20
|
|
|
19
|
-
A live demo is [available here](
|
|
21
|
+
A live demo is [available here](https://next.i18next.com/). This demo app is the [simple example](./examples/simple/) - nothing more, nothing less.
|
|
20
22
|
|
|
21
23
|
## Why next-i18next?
|
|
22
24
|
|
|
23
25
|
Easy to set up, easy to use: setup only takes a few steps, and configuration is simple.
|
|
24
26
|
|
|
25
|
-
No other requirements: `next-i18next` simplifies internationalisation for your [
|
|
27
|
+
No other requirements: `next-i18next` simplifies internationalisation for your [Next.js](https://nextjs.org/) app without extra dependencies.
|
|
26
28
|
|
|
27
29
|
Production ready: `next-i18next` supports passing translations and configuration options into pages as props with SSG/SSR support.
|
|
28
30
|
|
|
@@ -33,7 +35,7 @@ After configuration, `appWithTranslation` allows us to use the `t` (translate) f
|
|
|
33
35
|
|
|
34
36
|
Then we add `serverSideTranslation` to [getStaticProps](https://nextjs.org/docs/basic-features/data-fetching#getstaticprops-static-generation) or [getServerSideProps](https://nextjs.org/docs/basic-features/data-fetching#getserversideprops-server-side-rendering) (depending on your case) in our page-level components.
|
|
35
37
|
|
|
36
|
-
Now our
|
|
38
|
+
Now our Next.js app is fully translatable!
|
|
37
39
|
|
|
38
40
|
## Setup
|
|
39
41
|
|
|
@@ -65,7 +67,7 @@ If you want to structure your translations/namespaces in a custom way, you will
|
|
|
65
67
|
|
|
66
68
|
### 3. Project setup
|
|
67
69
|
|
|
68
|
-
First, create a `next-i18next.config.js` file in the root of your project. The syntax for the nested `i18n` object [comes from
|
|
70
|
+
First, create a `next-i18next.config.js` file in the root of your project. The syntax for the nested `i18n` object [comes from Next.js directly](https://nextjs.org/docs/advanced-features/i18n-routing).
|
|
69
71
|
|
|
70
72
|
This tells `next-i18next` what your `defaultLocale` and other locales are, so that it can preload translations on the server:
|
|
71
73
|
|
|
@@ -153,7 +155,7 @@ export const Footer = () => {
|
|
|
153
155
|
|
|
154
156
|
By default, `next-i18next` will send _all your namespaces_ down to the client on each initial request. This can be an appropriate approach for smaller apps with less content, but a lot of apps will benefit from splitting namespaces based on route.
|
|
155
157
|
|
|
156
|
-
To do that, you can pass an array of required namespaces for each page into `serverSideTranslations`. You can see this approach in [examples/simple/pages/index.js](./examples/simple/pages/index.js). Passing in an empty array of required namespaces will send no namespaces.
|
|
158
|
+
To do that, you can pass an array of required namespaces for each page into `serverSideTranslations`. You can see this approach in [examples/simple/pages/index.js](./examples/simple/pages/index.js). Passing in an empty array of required namespaces will send no namespaces.
|
|
157
159
|
|
|
158
160
|
Note: `useTranslation` provides namespaces to the component that you use it in. However, `serverSideTranslations` provides the total available namespaces to the entire React tree and belongs on the page level. Both are required.
|
|
159
161
|
|
|
@@ -179,7 +181,7 @@ module.exports = {
|
|
|
179
181
|
|
|
180
182
|
Some `i18next` plugins (which you can pass into `config.use`) are unserialisable, as they contain functions and other JavaScript primitives.
|
|
181
183
|
|
|
182
|
-
You may run into this if your use case is more advanced. You'll see
|
|
184
|
+
You may run into this if your use case is more advanced. You'll see Next.js throw an error like:
|
|
183
185
|
|
|
184
186
|
```
|
|
185
187
|
Error: Error serializing `._nextI18Next.userConfig.use[0].process` returned from `getStaticProps` in "/my-page".
|
|
@@ -213,6 +215,14 @@ export const getStaticProps = async ({ locale }) => ({
|
|
|
213
215
|
});
|
|
214
216
|
```
|
|
215
217
|
|
|
218
|
+
#### Client side loading of translations via HTTP
|
|
219
|
+
|
|
220
|
+
Since [v11.0.0](https://github.com/i18next/next-i18next/releases/tag/v11.0.0) next-i18next also provides support for client side loading of translations.
|
|
221
|
+
|
|
222
|
+
In some use cases, you might want to load a translation file dynamically without having to use `serverSideTranslations`. This can be especially useful for lazy-loaded components that you don't want slowing down pages.
|
|
223
|
+
|
|
224
|
+
More information about that can be found [here](https://github.com/i18next/i18next-http-backend/tree/master/example/next).
|
|
225
|
+
|
|
216
226
|
#### Reloading Resources in Development
|
|
217
227
|
|
|
218
228
|
Because resources are loaded once when the server is started, any changes made to your translation JSON files in development will not be loaded until the server is restarted.
|
|
@@ -231,30 +241,12 @@ This option will reload your translations whenever `serverSideTranslations` is c
|
|
|
231
241
|
| `localeStructure` | `'{{lng}}/{{ns}}'` | Ignored if `localePath` is a function. |
|
|
232
242
|
| `reloadOnPrerender` | `false` | |
|
|
233
243
|
| `serializeConfig` | `true` | |
|
|
234
|
-
| `strictMode` | `true` | |
|
|
235
244
|
| `use` (for plugins) | `[]` | |
|
|
236
245
|
|
|
237
246
|
`localePath` as a function is of the form `(locale: string, namespace: string, missing: boolean) => string` returning the entire path including filename and extension. When `missing` is true, return the path for the `addPath` option of `i18next-fs-backend`, when false, return the path for the `loadPath` option. [More info at the `i18next-fs-backend` repo.](https://github.com/i18next/i18next-fs-backend/tree/master#backend-options)
|
|
238
247
|
|
|
239
|
-
All other [i18next options](https://www.i18next.com/overview/configuration-options) can be passed in as well.
|
|
240
|
-
|
|
241
|
-
#### Loading Namespaces Dynamically Client Side
|
|
248
|
+
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.
|
|
242
249
|
|
|
243
|
-
In some use cases, you might want to load a translation file dynamically without having to use `serverSideTranslations`. This can be especially useful for lazy-loaded components that you don't want slowing down pages.
|
|
244
|
-
|
|
245
|
-
This can easily be done by using [addResourceBundle](https://www.i18next.com/how-to/add-or-load-translations#add-after-init):
|
|
246
|
-
|
|
247
|
-
```tsx
|
|
248
|
-
import { i18n } from 'next-i18next'
|
|
249
|
-
|
|
250
|
-
const Component = () => {
|
|
251
|
-
const { locale } = useRouter()
|
|
252
|
-
|
|
253
|
-
useEffect(() => {
|
|
254
|
-
i18n.addResourceBundle(locale, '<namespace name>')
|
|
255
|
-
}, [])
|
|
256
|
-
}
|
|
257
|
-
```
|
|
258
250
|
|
|
259
251
|
#### Custom interpolation prefix/suffix
|
|
260
252
|
|
|
@@ -277,15 +269,11 @@ For example, if you want to use `{` and `}` the config would look like this:
|
|
|
277
269
|
}
|
|
278
270
|
```
|
|
279
271
|
|
|
280
|
-
## Migration to v8
|
|
281
|
-
|
|
282
|
-
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)
|
|
283
|
-
|
|
284
272
|
## Notes
|
|
285
273
|
|
|
286
274
|
### Vercel and Netlify
|
|
287
275
|
|
|
288
|
-
Some serverless PaaS may not be able to locate the path of your translations and require additional configuration. If you have filesystem issues using `serverSideTranslations`, set `config.localePath` to use `path.resolve`. An example can be [found here](https://github.com/
|
|
276
|
+
Some serverless PaaS may not be able to locate the path of your translations and require additional configuration. If you have filesystem issues using `serverSideTranslations`, set `config.localePath` to use `path.resolve`. An example can be [found here](https://github.com/i18next/next-i18next/issues/1552#issuecomment-981156476).
|
|
289
277
|
|
|
290
278
|
|
|
291
279
|
### Docker
|
|
@@ -300,34 +288,73 @@ COPY --from=builder /app/next-i18next.config.js ./next-i18next.config.js
|
|
|
300
288
|
### Asynchronous i18next backends
|
|
301
289
|
|
|
302
290
|
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.
|
|
303
|
-
Since [React suspense is not yet supported for SSR](https://github.com/
|
|
291
|
+
Since [React suspense is not yet supported for SSR](https://github.com/i18next/next-i18next/issues/1255), this can be solved in 2 different ways:
|
|
304
292
|
|
|
305
293
|
**1) Preload the namespaces:**
|
|
306
294
|
|
|
307
|
-
Set the `ns` option, like in [this example](https://github.com/locize/next-i18next-locize/blob/main/next-i18next.config.js#
|
|
295
|
+
Set the `ns` option, like in [this example](https://github.com/locize/next-i18next-locize/blob/main/next-i18next.config.js#L48). Doing this will ensure all translation resources are loaded on initialization.
|
|
308
296
|
|
|
309
297
|
**2) Check the ready flag:**
|
|
310
298
|
|
|
311
299
|
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).
|
|
312
300
|
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).
|
|
313
301
|
|
|
302
|
+
|
|
303
|
+
### Static HTML Export SSG
|
|
304
|
+
|
|
305
|
+
Are you trying to generate a [static HTML export](https://nextjs.org/docs/advanced-features/static-html-export) by executing `next export` and are getting this error?
|
|
306
|
+
>Error: i18n support is not compatible with next export. See here for more info on deploying: https://nextjs.org/docs/deployment
|
|
307
|
+
|
|
308
|
+
But there's a way to workaround that with the help of [next-language-detector](https://github.com/i18next/next-language-detector).
|
|
309
|
+
Check out [this blog post](https://dev.to/adrai/static-html-export-with-i18n-compatibility-in-nextjs-8cd) and [this example project](./examples/ssg/).
|
|
310
|
+
[](https://dev.to/adrai/static-html-export-with-i18n-compatibility-in-nextjs-8cd)
|
|
311
|
+
|
|
314
312
|
## Contributors
|
|
315
313
|
|
|
316
314
|
Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds/all-contributors#emoji-key)):
|
|
317
315
|
|
|
318
316
|
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
|
|
319
|
-
<!-- prettier-ignore -->
|
|
320
|
-
|
|
317
|
+
<!-- prettier-ignore-start -->
|
|
318
|
+
<!-- markdownlint-disable -->
|
|
319
|
+
<table>
|
|
320
|
+
<tr>
|
|
321
|
+
<td align="center"><a href="https://locize.com/"><img src="https://avatars.githubusercontent.com/u/1086194?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Adriano Raiano</b></sub></a><br /><a href="#question-adrai" title="Answering Questions">💬</a> <a href="#blog-adrai" title="Blogposts">📝</a> <a href="https://github.com/i18next/next-i18next/issues?q=author%3Aadrai" title="Bug reports">🐛</a> <a href="https://github.com/i18next/next-i18next/commits?author=adrai" title="Code">💻</a> <a href="https://github.com/i18next/next-i18next/commits?author=adrai" title="Documentation">📖</a> <a href="#example-adrai" title="Examples">💡</a> <a href="https://github.com/i18next/next-i18next/pulls?q=is%3Apr+reviewed-by%3Aadrai" title="Reviewed Pull Requests">👀</a> <a href="https://github.com/i18next/next-i18next/commits?author=adrai" title="Tests">⚠️</a> <a href="#tutorial-adrai" title="Tutorials">✅</a></td>
|
|
322
|
+
<td align="center"><a href="https://isaachinman.com/"><img src="https://avatars.githubusercontent.com/u/10575782?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Isaac Hinman</b></sub></a><br /><a href="#question-isaachinman" title="Answering Questions">💬</a> <a href="https://github.com/i18next/next-i18next/commits?author=isaachinman" title="Code">💻</a> <a href="#content-isaachinman" title="Content">🖋</a> <a href="https://github.com/i18next/next-i18next/commits?author=isaachinman" title="Documentation">📖</a> <a href="#example-isaachinman" title="Examples">💡</a> <a href="https://github.com/i18next/next-i18next/pulls?q=is%3Apr+reviewed-by%3Aisaachinman" title="Reviewed Pull Requests">👀</a></td>
|
|
323
|
+
<td align="center"><a href="https://github.com/capellini"><img src="https://avatars3.githubusercontent.com/u/75311?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Rob Capellini</b></sub></a><br /><a href="https://github.com/i18next/next-i18next/commits?author=capellini" title="Code">💻</a> <a href="https://github.com/i18next/next-i18next/commits?author=capellini" title="Tests">⚠️</a></td>
|
|
324
|
+
<td align="center"><a href="https://en.kachkaev.ru"><img src="https://avatars3.githubusercontent.com/u/608862?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Alexander Kachkaev</b></sub></a><br /><a href="#talk-kachkaev" title="Talks">📢</a> <a href="#question-kachkaev" title="Answering Questions">💬</a> <a href="#ideas-kachkaev" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/i18next/next-i18next/commits?author=kachkaev" title="Code">💻</a> <a href="https://github.com/i18next/next-i18next/commits?author=kachkaev" title="Tests">⚠️</a></td>
|
|
325
|
+
<td align="center"><a href="https://github.com/felixmosh"><img src="https://avatars.githubusercontent.com/u/9304194?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Felix Mosheev</b></sub></a><br /><a href="#question-felixmosh" title="Answering Questions">💬</a> <a href="https://github.com/i18next/next-i18next/commits?author=felixmosh" title="Code">💻</a> <a href="#talk-felixmosh" title="Talks">📢</a> <a href="https://github.com/i18next/next-i18next/commits?author=felixmosh" title="Tests">⚠️</a></td>
|
|
326
|
+
<td align="center"><a href="https://kandelborg.dk"><img src="https://avatars1.githubusercontent.com/u/33042011?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Mathias Wøbbe</b></sub></a><br /><a href="https://github.com/i18next/next-i18next/commits?author=MathiasKandelborg" title="Code">💻</a> <a href="#ideas-MathiasKandelborg" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/i18next/next-i18next/commits?author=MathiasKandelborg" title="Tests">⚠️</a></td>
|
|
327
|
+
<td align="center"><a href="http://lucasfeliciano.com"><img src="https://avatars3.githubusercontent.com/u/968014?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Lucas Feliciano</b></sub></a><br /><a href="#ideas-lucasfeliciano" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/i18next/next-i18next/pulls?q=is%3Apr+reviewed-by%3Alucasfeliciano" title="Reviewed Pull Requests">👀</a></td>
|
|
328
|
+
</tr>
|
|
329
|
+
</table>
|
|
330
|
+
|
|
331
|
+
<!-- markdownlint-restore -->
|
|
332
|
+
<!-- prettier-ignore-end -->
|
|
321
333
|
<!-- ALL-CONTRIBUTORS-LIST:END -->
|
|
322
334
|
|
|
323
335
|
This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind welcome!
|
|
324
336
|
|
|
325
|
-
|
|
337
|
+
---
|
|
338
|
+
|
|
339
|
+
<h3 align="center">Gold Sponsors</h3>
|
|
340
|
+
|
|
341
|
+
<p align="center">
|
|
342
|
+
<a href="https://locize.com/" target="_blank">
|
|
343
|
+
<img src="https://raw.githubusercontent.com/i18next/i18next/master/assets/locize_sponsor_240.gif" width="240px">
|
|
344
|
+
</a>
|
|
345
|
+
<a href="https://localistars.com/" target="_blank">
|
|
346
|
+
<img src="https://raw.githubusercontent.com/i18next/i18next/master/assets/localistars_sponsor_240.gif" width="240px">
|
|
347
|
+
</a>
|
|
348
|
+
</p>
|
|
349
|
+
|
|
350
|
+
---
|
|
351
|
+
|
|
352
|
+
**localization as a service - locize.com**
|
|
353
|
+
|
|
354
|
+
Needing a translation management? Want to edit your translations with an InContext Editor? Use the original provided to you by the maintainers of i18next!
|
|
355
|
+
|
|
356
|
+

|
|
326
357
|
|
|
327
|
-
|
|
328
|
-
<img src="https://raw.githubusercontent.com/i18next/i18next/master/assets/locize_sponsor_240.gif" width="240px">
|
|
329
|
-
</a>
|
|
358
|
+
With using [locize](http://locize.com/?utm_source=next_i18next_readme&utm_medium=github) you directly support the future of i18next and react-i18next.
|
|
330
359
|
|
|
331
|
-
|
|
332
|
-
<img src="https://miro.medium.com/max/560/0*dLdslKvNsmtaH2uQ.png" width="240px">
|
|
333
|
-
</a>
|
|
360
|
+
---
|
|
@@ -41,6 +41,7 @@ Object.defineProperty(exports, "Trans", {
|
|
|
41
41
|
return _reactI18next.Trans;
|
|
42
42
|
}
|
|
43
43
|
});
|
|
44
|
+
exports.globalI18n = exports.appWithTranslation = void 0;
|
|
44
45
|
Object.defineProperty(exports, "useTranslation", {
|
|
45
46
|
enumerable: true,
|
|
46
47
|
get: function get() {
|
|
@@ -53,7 +54,6 @@ Object.defineProperty(exports, "withTranslation", {
|
|
|
53
54
|
return _reactI18next.withTranslation;
|
|
54
55
|
}
|
|
55
56
|
});
|
|
56
|
-
exports.appWithTranslation = exports.globalI18n = void 0;
|
|
57
57
|
|
|
58
58
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
59
59
|
|
|
@@ -86,23 +86,22 @@ 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;
|
|
89
|
+
var _nextI18Next$initialL, _props$router;
|
|
90
90
|
|
|
91
91
|
var _ref = props.pageProps,
|
|
92
92
|
_nextI18Next = _ref._nextI18Next;
|
|
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:
|
|
93
|
+
var locale = (_nextI18Next$initialL = _nextI18Next === null || _nextI18Next === void 0 ? void 0 : _nextI18Next.initialLocale) !== null && _nextI18Next$initialL !== void 0 ? _nextI18Next$initialL : props === null || props === void 0 ? void 0 : (_props$router = props.router) === null || _props$router === void 0 ? void 0 : _props$router.locale; // Memoize the instance and only re-initialize when either:
|
|
94
94
|
// 1. The route changes (non-shallowly)
|
|
95
95
|
// 2. Router locale changes
|
|
96
|
+
// 3. UserConfig override changes
|
|
96
97
|
|
|
97
98
|
var i18n = (0, _react.useMemo)(function () {
|
|
98
|
-
var _userConfig;
|
|
99
|
+
var _userConfig, _userConfig2, _userConfig2$i18n;
|
|
99
100
|
|
|
100
|
-
if (!_nextI18Next) return null;
|
|
101
|
-
var userConfig = _nextI18Next.userConfig;
|
|
102
|
-
var initialI18nStore = _nextI18Next.initialI18nStore;
|
|
103
|
-
var resources = configOverride !== null && configOverride !== void 0 && configOverride.resources ? configOverride.resources : initialI18nStore;
|
|
101
|
+
if (!_nextI18Next && !configOverride) return null;
|
|
102
|
+
var userConfig = configOverride !== null && configOverride !== void 0 ? configOverride : _nextI18Next === null || _nextI18Next === void 0 ? void 0 : _nextI18Next.userConfig;
|
|
104
103
|
|
|
105
|
-
if (userConfig
|
|
104
|
+
if (!userConfig && configOverride === null) {
|
|
106
105
|
throw new Error('appWithTranslation was called without a next-i18next config');
|
|
107
106
|
}
|
|
108
107
|
|
|
@@ -114,6 +113,15 @@ var appWithTranslation = function appWithTranslation(WrappedComponent) {
|
|
|
114
113
|
throw new Error('appWithTranslation was called without config.i18n');
|
|
115
114
|
}
|
|
116
115
|
|
|
116
|
+
if (!((_userConfig2 = userConfig) !== null && _userConfig2 !== void 0 && (_userConfig2$i18n = _userConfig2.i18n) !== null && _userConfig2$i18n !== void 0 && _userConfig2$i18n.defaultLocale)) {
|
|
117
|
+
throw new Error('config.i18n does not include a defaultLocale property');
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
var _ref2 = _nextI18Next || {},
|
|
121
|
+
initialI18nStore = _ref2.initialI18nStore;
|
|
122
|
+
|
|
123
|
+
var resources = configOverride !== null && configOverride !== void 0 && configOverride.resources ? configOverride.resources : initialI18nStore;
|
|
124
|
+
if (!locale) locale = userConfig.i18n.defaultLocale;
|
|
117
125
|
var instance = (0, _createClient["default"])(_objectSpread(_objectSpread({}, (0, _createConfig.createConfig)(_objectSpread(_objectSpread({}, userConfig), {}, {
|
|
118
126
|
lng: locale
|
|
119
127
|
}))), {}, {
|
|
@@ -122,7 +130,7 @@ var appWithTranslation = function appWithTranslation(WrappedComponent) {
|
|
|
122
130
|
})).i18n;
|
|
123
131
|
exports.globalI18n = globalI18n = instance;
|
|
124
132
|
return instance;
|
|
125
|
-
}, [_nextI18Next, locale]);
|
|
133
|
+
}, [_nextI18Next, locale, configOverride]);
|
|
126
134
|
return i18n !== null ? __jsx(_reactI18next.I18nextProvider, {
|
|
127
135
|
i18n: i18n
|
|
128
136
|
}, __jsx(WrappedComponent, (0, _extends2["default"])({
|
|
@@ -4,8 +4,6 @@ require("core-js/modules/es.object.keys.js");
|
|
|
4
4
|
|
|
5
5
|
require("core-js/modules/es.symbol.js");
|
|
6
6
|
|
|
7
|
-
require("core-js/modules/es.array.filter.js");
|
|
8
|
-
|
|
9
7
|
require("core-js/modules/es.object.get-own-property-descriptor.js");
|
|
10
8
|
|
|
11
9
|
require("core-js/modules/web.dom-collections.for-each.js");
|
|
@@ -31,10 +29,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
31
29
|
});
|
|
32
30
|
exports.createConfig = void 0;
|
|
33
31
|
|
|
34
|
-
require("core-js/modules/es.array.
|
|
32
|
+
require("core-js/modules/es.array.filter.js");
|
|
35
33
|
|
|
36
34
|
require("core-js/modules/es.object.to-string.js");
|
|
37
35
|
|
|
36
|
+
require("core-js/modules/es.array.some.js");
|
|
37
|
+
|
|
38
38
|
require("core-js/modules/es.regexp.exec.js");
|
|
39
39
|
|
|
40
40
|
require("core-js/modules/es.string.replace.js");
|
|
@@ -67,6 +67,8 @@ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers
|
|
|
67
67
|
|
|
68
68
|
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
69
69
|
|
|
70
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
71
|
+
|
|
70
72
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
71
73
|
|
|
72
74
|
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
@@ -107,13 +109,15 @@ var createConfig = function createConfig(userConfig) {
|
|
|
107
109
|
|
|
108
110
|
var defaultNS = combinedConfig.defaultNS,
|
|
109
111
|
lng = combinedConfig.lng,
|
|
110
|
-
locales = combinedConfig.locales,
|
|
111
112
|
localeExtension = combinedConfig.localeExtension,
|
|
112
113
|
localePath = combinedConfig.localePath,
|
|
113
114
|
localeStructure = combinedConfig.localeStructure;
|
|
115
|
+
var locales = combinedConfig.locales.filter(function (l) {
|
|
116
|
+
return l !== 'default';
|
|
117
|
+
});
|
|
114
118
|
/**
|
|
115
119
|
* Skips translation file resolution while in cimode
|
|
116
|
-
* https://github.com/
|
|
120
|
+
* https://github.com/i18next/next-i18next/pull/851#discussion_r503113620
|
|
117
121
|
*/
|
|
118
122
|
|
|
119
123
|
if (lng === 'cimode') {
|
|
@@ -122,6 +126,12 @@ var createConfig = function createConfig(userConfig) {
|
|
|
122
126
|
|
|
123
127
|
if (typeof combinedConfig.fallbackLng === 'undefined') {
|
|
124
128
|
combinedConfig.fallbackLng = combinedConfig.defaultLocale;
|
|
129
|
+
|
|
130
|
+
if (combinedConfig.fallbackLng === 'default') {
|
|
131
|
+
var _locales = (0, _slicedToArray2["default"])(locales, 1);
|
|
132
|
+
|
|
133
|
+
combinedConfig.fallbackLng = _locales[0];
|
|
134
|
+
}
|
|
125
135
|
}
|
|
126
136
|
|
|
127
137
|
var hasCustomBackend = userConfig === null || userConfig === void 0 ? void 0 : (_userConfig$use = userConfig.use) === null || _userConfig$use === void 0 ? void 0 : _userConfig$use.some(function (b) {
|
|
@@ -136,7 +146,7 @@ var createConfig = function createConfig(userConfig) {
|
|
|
136
146
|
|
|
137
147
|
var path = require('path'); //
|
|
138
148
|
// Validate defaultNS
|
|
139
|
-
// https://github.com/
|
|
149
|
+
// https://github.com/i18next/next-i18next/issues/358
|
|
140
150
|
//
|
|
141
151
|
|
|
142
152
|
|
package/dist/commonjs/index.js
CHANGED
|
@@ -23,28 +23,28 @@ Object.defineProperty(exports, "Translation", {
|
|
|
23
23
|
return _reactI18next.Translation;
|
|
24
24
|
}
|
|
25
25
|
});
|
|
26
|
-
Object.defineProperty(exports, "
|
|
26
|
+
Object.defineProperty(exports, "appWithTranslation", {
|
|
27
27
|
enumerable: true,
|
|
28
28
|
get: function get() {
|
|
29
|
-
return
|
|
29
|
+
return _appWithTranslation.appWithTranslation;
|
|
30
30
|
}
|
|
31
31
|
});
|
|
32
|
-
Object.defineProperty(exports, "
|
|
32
|
+
Object.defineProperty(exports, "i18n", {
|
|
33
33
|
enumerable: true,
|
|
34
34
|
get: function get() {
|
|
35
|
-
return
|
|
35
|
+
return _appWithTranslation.globalI18n;
|
|
36
36
|
}
|
|
37
37
|
});
|
|
38
|
-
Object.defineProperty(exports, "
|
|
38
|
+
Object.defineProperty(exports, "useTranslation", {
|
|
39
39
|
enumerable: true,
|
|
40
40
|
get: function get() {
|
|
41
|
-
return
|
|
41
|
+
return _reactI18next.useTranslation;
|
|
42
42
|
}
|
|
43
43
|
});
|
|
44
|
-
Object.defineProperty(exports, "
|
|
44
|
+
Object.defineProperty(exports, "withTranslation", {
|
|
45
45
|
enumerable: true,
|
|
46
46
|
get: function get() {
|
|
47
|
-
return
|
|
47
|
+
return _reactI18next.withTranslation;
|
|
48
48
|
}
|
|
49
49
|
});
|
|
50
50
|
|
package/dist/commonjs/types.js
CHANGED
|
@@ -5,28 +5,16 @@ require("core-js/modules/es.object.define-property.js");
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
Object.defineProperty(exports, "
|
|
9
|
-
enumerable: true,
|
|
10
|
-
get: function get() {
|
|
11
|
-
return _reactI18next.I18nContext;
|
|
12
|
-
}
|
|
13
|
-
});
|
|
14
|
-
Object.defineProperty(exports, "useTranslation", {
|
|
15
|
-
enumerable: true,
|
|
16
|
-
get: function get() {
|
|
17
|
-
return _reactI18next.useTranslation;
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
Object.defineProperty(exports, "Trans", {
|
|
8
|
+
Object.defineProperty(exports, "DefaultNamespace", {
|
|
21
9
|
enumerable: true,
|
|
22
10
|
get: function get() {
|
|
23
|
-
return _reactI18next.
|
|
11
|
+
return _reactI18next.DefaultNamespace;
|
|
24
12
|
}
|
|
25
13
|
});
|
|
26
|
-
Object.defineProperty(exports, "
|
|
14
|
+
Object.defineProperty(exports, "I18nContext", {
|
|
27
15
|
enumerable: true,
|
|
28
16
|
get: function get() {
|
|
29
|
-
return _reactI18next.
|
|
17
|
+
return _reactI18next.I18nContext;
|
|
30
18
|
}
|
|
31
19
|
});
|
|
32
20
|
Object.defineProperty(exports, "Resources", {
|
|
@@ -35,10 +23,10 @@ Object.defineProperty(exports, "Resources", {
|
|
|
35
23
|
return _reactI18next.Resources;
|
|
36
24
|
}
|
|
37
25
|
});
|
|
38
|
-
Object.defineProperty(exports, "
|
|
26
|
+
Object.defineProperty(exports, "Trans", {
|
|
39
27
|
enumerable: true,
|
|
40
28
|
get: function get() {
|
|
41
|
-
return _reactI18next.
|
|
29
|
+
return _reactI18next.Trans;
|
|
42
30
|
}
|
|
43
31
|
});
|
|
44
32
|
Object.defineProperty(exports, "Translation", {
|
|
@@ -59,6 +47,18 @@ Object.defineProperty(exports, "i18n", {
|
|
|
59
47
|
return _.i18n;
|
|
60
48
|
}
|
|
61
49
|
});
|
|
50
|
+
Object.defineProperty(exports, "useTranslation", {
|
|
51
|
+
enumerable: true,
|
|
52
|
+
get: function get() {
|
|
53
|
+
return _reactI18next.useTranslation;
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
Object.defineProperty(exports, "withTranslation", {
|
|
57
|
+
enumerable: true,
|
|
58
|
+
get: function get() {
|
|
59
|
+
return _reactI18next.withTranslation;
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
62
|
|
|
63
63
|
var _reactI18next = require("react-i18next");
|
|
64
64
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
function _extends() { _extends = Object.assign
|
|
1
|
+
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
2
2
|
|
|
3
3
|
import React, { useMemo } from 'react';
|
|
4
4
|
import hoistNonReactStatics from 'hoist-non-react-statics';
|
|
@@ -12,23 +12,16 @@ export const appWithTranslation = (WrappedComponent, configOverride = null) => {
|
|
|
12
12
|
const {
|
|
13
13
|
_nextI18Next
|
|
14
14
|
} = props.pageProps;
|
|
15
|
-
|
|
15
|
+
let locale = _nextI18Next?.initialLocale ?? props?.router?.locale; // Memoize the instance and only re-initialize when either:
|
|
16
16
|
// 1. The route changes (non-shallowly)
|
|
17
17
|
// 2. Router locale changes
|
|
18
|
+
// 3. UserConfig override changes
|
|
18
19
|
|
|
19
20
|
const i18n = useMemo(() => {
|
|
20
|
-
|
|
21
|
+
if (!_nextI18Next && !configOverride) return null;
|
|
22
|
+
let userConfig = configOverride ?? _nextI18Next?.userConfig;
|
|
21
23
|
|
|
22
|
-
if (!
|
|
23
|
-
let {
|
|
24
|
-
userConfig
|
|
25
|
-
} = _nextI18Next;
|
|
26
|
-
const {
|
|
27
|
-
initialI18nStore
|
|
28
|
-
} = _nextI18Next;
|
|
29
|
-
const resources = configOverride !== null && configOverride !== void 0 && configOverride.resources ? configOverride.resources : initialI18nStore;
|
|
30
|
-
|
|
31
|
-
if (userConfig === null && configOverride === null) {
|
|
24
|
+
if (!userConfig && configOverride === null) {
|
|
32
25
|
throw new Error('appWithTranslation was called without a next-i18next config');
|
|
33
26
|
}
|
|
34
27
|
|
|
@@ -36,10 +29,19 @@ export const appWithTranslation = (WrappedComponent, configOverride = null) => {
|
|
|
36
29
|
userConfig = configOverride;
|
|
37
30
|
}
|
|
38
31
|
|
|
39
|
-
if (!
|
|
32
|
+
if (!userConfig?.i18n) {
|
|
40
33
|
throw new Error('appWithTranslation was called without config.i18n');
|
|
41
34
|
}
|
|
42
35
|
|
|
36
|
+
if (!userConfig?.i18n?.defaultLocale) {
|
|
37
|
+
throw new Error('config.i18n does not include a defaultLocale property');
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const {
|
|
41
|
+
initialI18nStore
|
|
42
|
+
} = _nextI18Next || {};
|
|
43
|
+
const resources = configOverride?.resources ? configOverride.resources : initialI18nStore;
|
|
44
|
+
if (!locale) locale = userConfig.i18n.defaultLocale;
|
|
43
45
|
const instance = createClient({ ...createConfig({ ...userConfig,
|
|
44
46
|
lng: locale
|
|
45
47
|
}),
|
|
@@ -48,7 +50,7 @@ export const appWithTranslation = (WrappedComponent, configOverride = null) => {
|
|
|
48
50
|
}).i18n;
|
|
49
51
|
globalI18n = instance;
|
|
50
52
|
return instance;
|
|
51
|
-
}, [_nextI18Next, locale]);
|
|
53
|
+
}, [_nextI18Next, locale, configOverride]);
|
|
52
54
|
return i18n !== null ? /*#__PURE__*/React.createElement(I18nextProvider, {
|
|
53
55
|
i18n: i18n
|
|
54
56
|
}, /*#__PURE__*/React.createElement(WrappedComponent, _extends({
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { defaultConfig } from './defaultConfig';
|
|
2
2
|
const deepMergeObjects = ['backend', 'detection'];
|
|
3
3
|
export const createConfig = userConfig => {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
if (typeof (userConfig === null || userConfig === void 0 ? void 0 : userConfig.lng) !== 'string') {
|
|
4
|
+
if (typeof userConfig?.lng !== 'string') {
|
|
7
5
|
throw new Error('config.lng was not passed into createConfig');
|
|
8
6
|
} //
|
|
9
7
|
// Initial merge of default and user-provided config
|
|
@@ -26,14 +24,14 @@ export const createConfig = userConfig => {
|
|
|
26
24
|
const {
|
|
27
25
|
defaultNS,
|
|
28
26
|
lng,
|
|
29
|
-
locales,
|
|
30
27
|
localeExtension,
|
|
31
28
|
localePath,
|
|
32
29
|
localeStructure
|
|
33
30
|
} = combinedConfig;
|
|
31
|
+
const locales = combinedConfig.locales.filter(l => l !== 'default');
|
|
34
32
|
/**
|
|
35
33
|
* Skips translation file resolution while in cimode
|
|
36
|
-
* https://github.com/
|
|
34
|
+
* https://github.com/i18next/next-i18next/pull/851#discussion_r503113620
|
|
37
35
|
*/
|
|
38
36
|
|
|
39
37
|
if (lng === 'cimode') {
|
|
@@ -42,9 +40,10 @@ export const createConfig = userConfig => {
|
|
|
42
40
|
|
|
43
41
|
if (typeof combinedConfig.fallbackLng === 'undefined') {
|
|
44
42
|
combinedConfig.fallbackLng = combinedConfig.defaultLocale;
|
|
43
|
+
if (combinedConfig.fallbackLng === 'default') [combinedConfig.fallbackLng] = locales;
|
|
45
44
|
}
|
|
46
45
|
|
|
47
|
-
const hasCustomBackend = userConfig
|
|
46
|
+
const hasCustomBackend = userConfig?.use?.some(b => b.type === 'backend');
|
|
48
47
|
|
|
49
48
|
if (!process.browser && typeof window === 'undefined') {
|
|
50
49
|
combinedConfig.preload = locales;
|
|
@@ -54,16 +53,14 @@ export const createConfig = userConfig => {
|
|
|
54
53
|
|
|
55
54
|
const path = require('path'); //
|
|
56
55
|
// Validate defaultNS
|
|
57
|
-
// https://github.com/
|
|
56
|
+
// https://github.com/i18next/next-i18next/issues/358
|
|
58
57
|
//
|
|
59
58
|
|
|
60
59
|
|
|
61
60
|
if (typeof defaultNS === 'string' && typeof lng !== 'undefined') {
|
|
62
61
|
if (typeof localePath === 'string') {
|
|
63
|
-
|
|
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) ?? '}}';
|
|
62
|
+
const prefix = userConfig?.interpolation?.prefix ?? '{{';
|
|
63
|
+
const suffix = userConfig?.interpolation?.suffix ?? '}}';
|
|
67
64
|
const defaultLocaleStructure = localeStructure.replace(`${prefix}lng${suffix}`, lng).replace(`${prefix}ns${suffix}`, defaultNS);
|
|
68
65
|
const defaultFile = `/${defaultLocaleStructure}.${localeExtension}`;
|
|
69
66
|
const defaultNSPath = path.join(localePath, defaultFile);
|
|
@@ -4,9 +4,7 @@ export default (config => {
|
|
|
4
4
|
let initPromise;
|
|
5
5
|
|
|
6
6
|
if (!instance.isInitialized) {
|
|
7
|
-
|
|
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));
|
|
7
|
+
config?.use?.forEach(x => instance.use(x));
|
|
10
8
|
initPromise = instance.init(config);
|
|
11
9
|
} else {
|
|
12
10
|
initPromise = Promise.resolve(i18n.t);
|
|
@@ -16,15 +16,13 @@ export default (config => {
|
|
|
16
16
|
let initPromise;
|
|
17
17
|
|
|
18
18
|
if (!instance.isInitialized) {
|
|
19
|
-
|
|
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');
|
|
19
|
+
const hasCustomBackend = config?.use?.some(b => b.type === 'backend');
|
|
22
20
|
|
|
23
21
|
if (!hasCustomBackend) {
|
|
24
22
|
instance.use(i18nextFSBackend);
|
|
25
23
|
}
|
|
26
24
|
|
|
27
|
-
config
|
|
25
|
+
config?.use?.forEach(x => instance.use(x));
|
|
28
26
|
initPromise = instance.init(config);
|
|
29
27
|
} else {
|
|
30
28
|
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
|
|
60
|
+
await globalI18n?.reloadResources();
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
const {
|
|
@@ -17,23 +17,22 @@ 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;
|
|
20
|
+
var _nextI18Next$initialL, _props$router;
|
|
21
21
|
|
|
22
22
|
var _ref = props.pageProps,
|
|
23
23
|
_nextI18Next = _ref._nextI18Next;
|
|
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:
|
|
24
|
+
var locale = (_nextI18Next$initialL = _nextI18Next === null || _nextI18Next === void 0 ? void 0 : _nextI18Next.initialLocale) !== null && _nextI18Next$initialL !== void 0 ? _nextI18Next$initialL : props === null || props === void 0 ? void 0 : (_props$router = props.router) === null || _props$router === void 0 ? void 0 : _props$router.locale; // Memoize the instance and only re-initialize when either:
|
|
25
25
|
// 1. The route changes (non-shallowly)
|
|
26
26
|
// 2. Router locale changes
|
|
27
|
+
// 3. UserConfig override changes
|
|
27
28
|
|
|
28
29
|
var i18n = useMemo(function () {
|
|
29
|
-
var _userConfig;
|
|
30
|
+
var _userConfig, _userConfig2, _userConfig2$i18n;
|
|
30
31
|
|
|
31
|
-
if (!_nextI18Next) return null;
|
|
32
|
-
var userConfig = _nextI18Next.userConfig;
|
|
33
|
-
var initialI18nStore = _nextI18Next.initialI18nStore;
|
|
34
|
-
var resources = configOverride !== null && configOverride !== void 0 && configOverride.resources ? configOverride.resources : initialI18nStore;
|
|
32
|
+
if (!_nextI18Next && !configOverride) return null;
|
|
33
|
+
var userConfig = configOverride !== null && configOverride !== void 0 ? configOverride : _nextI18Next === null || _nextI18Next === void 0 ? void 0 : _nextI18Next.userConfig;
|
|
35
34
|
|
|
36
|
-
if (userConfig
|
|
35
|
+
if (!userConfig && configOverride === null) {
|
|
37
36
|
throw new Error('appWithTranslation was called without a next-i18next config');
|
|
38
37
|
}
|
|
39
38
|
|
|
@@ -45,6 +44,15 @@ export var appWithTranslation = function appWithTranslation(WrappedComponent) {
|
|
|
45
44
|
throw new Error('appWithTranslation was called without config.i18n');
|
|
46
45
|
}
|
|
47
46
|
|
|
47
|
+
if (!((_userConfig2 = userConfig) !== null && _userConfig2 !== void 0 && (_userConfig2$i18n = _userConfig2.i18n) !== null && _userConfig2$i18n !== void 0 && _userConfig2$i18n.defaultLocale)) {
|
|
48
|
+
throw new Error('config.i18n does not include a defaultLocale property');
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
var _ref2 = _nextI18Next || {},
|
|
52
|
+
initialI18nStore = _ref2.initialI18nStore;
|
|
53
|
+
|
|
54
|
+
var resources = configOverride !== null && configOverride !== void 0 && configOverride.resources ? configOverride.resources : initialI18nStore;
|
|
55
|
+
if (!locale) locale = userConfig.i18n.defaultLocale;
|
|
48
56
|
var instance = createClient(_objectSpread(_objectSpread({}, createConfig(_objectSpread(_objectSpread({}, userConfig), {}, {
|
|
49
57
|
lng: locale
|
|
50
58
|
}))), {}, {
|
|
@@ -53,7 +61,7 @@ export var appWithTranslation = function appWithTranslation(WrappedComponent) {
|
|
|
53
61
|
})).i18n;
|
|
54
62
|
globalI18n = instance;
|
|
55
63
|
return instance;
|
|
56
|
-
}, [_nextI18Next, locale]);
|
|
64
|
+
}, [_nextI18Next, locale, configOverride]);
|
|
57
65
|
return i18n !== null ? __jsx(I18nextProvider, {
|
|
58
66
|
i18n: i18n
|
|
59
67
|
}, __jsx(WrappedComponent, _extends({
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
2
|
import _typeof from "@babel/runtime/helpers/typeof";
|
|
3
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
4
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
4
5
|
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
5
6
|
var _excluded = ["i18n"],
|
|
@@ -37,13 +38,15 @@ export var createConfig = function createConfig(userConfig) {
|
|
|
37
38
|
|
|
38
39
|
var defaultNS = combinedConfig.defaultNS,
|
|
39
40
|
lng = combinedConfig.lng,
|
|
40
|
-
locales = combinedConfig.locales,
|
|
41
41
|
localeExtension = combinedConfig.localeExtension,
|
|
42
42
|
localePath = combinedConfig.localePath,
|
|
43
43
|
localeStructure = combinedConfig.localeStructure;
|
|
44
|
+
var locales = combinedConfig.locales.filter(function (l) {
|
|
45
|
+
return l !== 'default';
|
|
46
|
+
});
|
|
44
47
|
/**
|
|
45
48
|
* Skips translation file resolution while in cimode
|
|
46
|
-
* https://github.com/
|
|
49
|
+
* https://github.com/i18next/next-i18next/pull/851#discussion_r503113620
|
|
47
50
|
*/
|
|
48
51
|
|
|
49
52
|
if (lng === 'cimode') {
|
|
@@ -52,6 +55,12 @@ export var createConfig = function createConfig(userConfig) {
|
|
|
52
55
|
|
|
53
56
|
if (typeof combinedConfig.fallbackLng === 'undefined') {
|
|
54
57
|
combinedConfig.fallbackLng = combinedConfig.defaultLocale;
|
|
58
|
+
|
|
59
|
+
if (combinedConfig.fallbackLng === 'default') {
|
|
60
|
+
var _locales = _slicedToArray(locales, 1);
|
|
61
|
+
|
|
62
|
+
combinedConfig.fallbackLng = _locales[0];
|
|
63
|
+
}
|
|
55
64
|
}
|
|
56
65
|
|
|
57
66
|
var hasCustomBackend = userConfig === null || userConfig === void 0 ? void 0 : (_userConfig$use = userConfig.use) === null || _userConfig$use === void 0 ? void 0 : _userConfig$use.some(function (b) {
|
|
@@ -66,7 +75,7 @@ export var createConfig = function createConfig(userConfig) {
|
|
|
66
75
|
|
|
67
76
|
var path = require('path'); //
|
|
68
77
|
// Validate defaultNS
|
|
69
|
-
// https://github.com/
|
|
78
|
+
// https://github.com/i18next/next-i18next/issues/358
|
|
70
79
|
//
|
|
71
80
|
|
|
72
81
|
|
package/dist/types/types.d.ts
CHANGED
|
@@ -12,7 +12,6 @@ export declare type UserConfig = {
|
|
|
12
12
|
localeStructure?: string;
|
|
13
13
|
reloadOnPrerender?: boolean;
|
|
14
14
|
serializeConfig?: boolean;
|
|
15
|
-
strictMode?: boolean;
|
|
16
15
|
use?: any[];
|
|
17
16
|
} & InitOptions;
|
|
18
17
|
export declare type InternalConfig = Omit<UserConfig, 'i18n'> & NextJsI18NConfig & {
|
package/package.json
CHANGED
|
@@ -1,12 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "next-i18next",
|
|
3
|
-
"version": "
|
|
4
|
-
"repository": "git@github.com:
|
|
5
|
-
"author": "
|
|
6
|
-
"funding":
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
3
|
+
"version": "11.1.1",
|
|
4
|
+
"repository": "git@github.com:i18next/next-i18next.git",
|
|
5
|
+
"author": "i18next",
|
|
6
|
+
"funding": [
|
|
7
|
+
{
|
|
8
|
+
"type": "individual",
|
|
9
|
+
"url": "https://locize.com"
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"type": "individual",
|
|
13
|
+
"url": "https://locize.com/i18next.html"
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
"type": "individual",
|
|
17
|
+
"url": "https://www.i18next.com/how-to/faq#i18next-is-awesome.-how-can-i-support-the-project"
|
|
18
|
+
}
|
|
19
|
+
],
|
|
10
20
|
"main": "dist/commonjs/index.js",
|
|
11
21
|
"module": "dist/esm/index.js",
|
|
12
22
|
"types": "dist/types/types.d.ts",
|
|
@@ -28,94 +38,105 @@
|
|
|
28
38
|
"scripts": {
|
|
29
39
|
"check-types": "tsc --noEmit",
|
|
30
40
|
"lint": "eslint src examples",
|
|
31
|
-
"clean": "rm -rf examples/simple/.next && rm -rf dist && mkdir dist",
|
|
41
|
+
"clean": "rm -rf examples/simple/.next && rm -rf examples/ssg/.next && rm -rf dist && mkdir dist",
|
|
32
42
|
"build:es": "BABEL_ENV=es babel src --extensions '.ts,.tsx' --out-dir dist/es --copy-files",
|
|
33
43
|
"build:cjs": "BABEL_ENV=cjs babel src --extensions '.ts,.tsx' --out-dir dist/commonjs --copy-files",
|
|
34
44
|
"build:esm": "BABEL_ENV=esm babel src --extensions '.ts,.tsx' --out-dir dist/esm --copy-files",
|
|
35
45
|
"build:types": "tsc --noEmit false --declaration --emitDeclarationOnly --outDir dist/types",
|
|
36
|
-
"build": "
|
|
37
|
-
"build:
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
46
|
+
"build": "npm run clean && npm run build:cjs && npm run build:es && npm run build:esm && npm run build:types",
|
|
47
|
+
"build:example:simple": "cd examples/simple && npm run build",
|
|
48
|
+
"build:example:ssg": "cd examples/ssg && npm run build",
|
|
49
|
+
"prepublishOnly": "npm run build",
|
|
50
|
+
"example": "npm run example:simple",
|
|
51
|
+
"example:prod": "npm run example:simple:prod",
|
|
52
|
+
"example:simple": "npm run build && cp -r dist examples/simple/node_modules/next-i18next && cd examples/simple && npm run dev",
|
|
53
|
+
"example:simple:prod": "npm run build:example:simple && cd examples/simple && npm run start",
|
|
54
|
+
"example:ssg": "npm run build && cp -r dist examples/ssg/node_modules/next-i18next && cd examples/ssg && npm run dev",
|
|
55
|
+
"example:ssg:prod": "npm run build:example:ssg && cd examples/ssg && npm run start",
|
|
56
|
+
"cypress": "cypress run --config-file cypress/cypress.json",
|
|
57
|
+
"test": "npm run check-types && npm run clean && npm run build && npm run build:example:simple && bundlesize && NODE_ENV=test jest --maxWorkers=1 --silent",
|
|
58
|
+
"test:e2e": "start-server-and-test 'cd examples/simple && npm run start' 3000 'npm run cypress'",
|
|
44
59
|
"contributors:check": "all-contributors check",
|
|
45
60
|
"contributors:add": "all-contributors add",
|
|
46
|
-
"contributors:generate": "all-contributors generate"
|
|
61
|
+
"contributors:generate": "all-contributors generate",
|
|
62
|
+
"preversion": "npm run test && npm run build && git push",
|
|
63
|
+
"postversion": "git push && git push --tags && npm run release",
|
|
64
|
+
"release": "gh-release"
|
|
47
65
|
},
|
|
48
66
|
"husky": {
|
|
49
67
|
"hooks": {
|
|
50
|
-
"pre-commit": "
|
|
68
|
+
"pre-commit": "npm run lint"
|
|
51
69
|
}
|
|
52
70
|
},
|
|
53
71
|
"bundlesize": [
|
|
54
72
|
{
|
|
55
|
-
"path": "./examples/simple/.next/static/chunks
|
|
56
|
-
"maxSize": "
|
|
73
|
+
"path": "./examples/simple/.next/static/chunks/*.js",
|
|
74
|
+
"maxSize": "50 kB"
|
|
57
75
|
},
|
|
58
76
|
{
|
|
59
77
|
"path": "./examples/simple/.next/static/chunks/main*.js",
|
|
60
|
-
"maxSize": "
|
|
78
|
+
"maxSize": "35 kB"
|
|
61
79
|
},
|
|
62
80
|
{
|
|
63
81
|
"path": "./examples/simple/.next/static/chunks/webpack*.js",
|
|
64
|
-
"maxSize": "
|
|
82
|
+
"maxSize": "770 B"
|
|
65
83
|
}
|
|
66
84
|
],
|
|
67
85
|
"devDependencies": {
|
|
68
|
-
"@babel/cli": "^7.
|
|
69
|
-
"@babel/core": "^7.
|
|
70
|
-
"@babel/plugin-proposal-class-properties": "^7.
|
|
71
|
-
"@babel/plugin-transform-runtime": "^7.
|
|
72
|
-
"@babel/preset-env": "^7.
|
|
73
|
-
"@babel/preset-react": "^7.
|
|
74
|
-
"@babel/preset-typescript": "^7.
|
|
75
|
-
"@testing-library/react": "^
|
|
86
|
+
"@babel/cli": "^7.18.6",
|
|
87
|
+
"@babel/core": "^7.18.6",
|
|
88
|
+
"@babel/plugin-proposal-class-properties": "^7.18.6",
|
|
89
|
+
"@babel/plugin-transform-runtime": "^7.18.6",
|
|
90
|
+
"@babel/preset-env": "^7.18.6",
|
|
91
|
+
"@babel/preset-react": "^7.18.6",
|
|
92
|
+
"@babel/preset-typescript": "^7.18.6",
|
|
93
|
+
"@testing-library/react": "^13.3.0",
|
|
76
94
|
"@types/i18next-fs-backend": "^1.1.2",
|
|
77
|
-
"@types/jest": "^
|
|
78
|
-
"@types/node": "^
|
|
79
|
-
"@types/react": "^
|
|
80
|
-
"@types/react-dom": "^
|
|
81
|
-
"@types/testing-library__cypress": "^5.0.
|
|
82
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
83
|
-
"@typescript-eslint/parser": "^
|
|
84
|
-
"all-contributors-cli": "^6.
|
|
95
|
+
"@types/jest": "^28.1.4",
|
|
96
|
+
"@types/node": "^18.0.3",
|
|
97
|
+
"@types/react": "^18.0.15",
|
|
98
|
+
"@types/react-dom": "^18.0.6",
|
|
99
|
+
"@types/testing-library__cypress": "^5.0.9",
|
|
100
|
+
"@typescript-eslint/eslint-plugin": "^5.30.5",
|
|
101
|
+
"@typescript-eslint/parser": "^5.30.5",
|
|
102
|
+
"all-contributors-cli": "^6.20.0",
|
|
85
103
|
"babel-core": "^7.0.0-bridge.0",
|
|
86
|
-
"babel-plugin-add-module-exports": "^1.0.
|
|
104
|
+
"babel-plugin-add-module-exports": "^1.0.4",
|
|
87
105
|
"babel-plugin-transform-async-to-generator": "^6.24.1",
|
|
88
|
-
"bundlesize": "^0.18.
|
|
106
|
+
"bundlesize": "^0.18.1",
|
|
89
107
|
"cypress": "^9.1.1",
|
|
90
|
-
"eslint": "^
|
|
91
|
-
"eslint-plugin-cypress": "^2.
|
|
92
|
-
"eslint-plugin-import": "^2.
|
|
93
|
-
"eslint-plugin-jest": "^
|
|
108
|
+
"eslint": "^8.19.0",
|
|
109
|
+
"eslint-plugin-cypress": "^2.12.1",
|
|
110
|
+
"eslint-plugin-import": "^2.26.0",
|
|
111
|
+
"eslint-plugin-jest": "^26.5.3",
|
|
94
112
|
"eslint-plugin-prefer-arrow": "^1.2.3",
|
|
95
|
-
"eslint-plugin-react": "^7.
|
|
113
|
+
"eslint-plugin-react": "^7.30.1",
|
|
96
114
|
"eslint-plugin-typescript-sort-keys": "^2.1.0",
|
|
115
|
+
"gh-release": "6.0.1",
|
|
97
116
|
"husky": "^3.0.0",
|
|
98
117
|
"jest": "^26.6.3",
|
|
99
|
-
"next": "^12.
|
|
100
|
-
"react": "^
|
|
101
|
-
"react-dom": "^
|
|
102
|
-
"start-server-and-test": "^1.
|
|
103
|
-
"typescript": "^4.
|
|
118
|
+
"next": "^12.2.0",
|
|
119
|
+
"react": "^18.2.0",
|
|
120
|
+
"react-dom": "^18.2.0",
|
|
121
|
+
"start-server-and-test": "^1.14.0",
|
|
122
|
+
"typescript": "^4.7.4"
|
|
104
123
|
},
|
|
105
124
|
"dependencies": {
|
|
106
|
-
"@babel/runtime": "^7.
|
|
125
|
+
"@babel/runtime": "^7.18.6",
|
|
107
126
|
"@types/hoist-non-react-statics": "^3.3.1",
|
|
108
127
|
"core-js": "^3",
|
|
109
|
-
"hoist-non-react-statics": "^3.2
|
|
110
|
-
"i18next": "^21.
|
|
111
|
-
"i18next-fs-backend": "^1.
|
|
112
|
-
"react-i18next": "^11.
|
|
128
|
+
"hoist-non-react-statics": "^3.3.2",
|
|
129
|
+
"i18next": "^21.8.13",
|
|
130
|
+
"i18next-fs-backend": "^1.1.4",
|
|
131
|
+
"react-i18next": "^11.18.0"
|
|
113
132
|
},
|
|
114
133
|
"peerDependencies": {
|
|
115
134
|
"next": ">= 10.0.0",
|
|
116
135
|
"react": ">= 16.8.0"
|
|
117
136
|
},
|
|
118
137
|
"resolutions": {
|
|
119
|
-
"i18next
|
|
138
|
+
"i18next": ">=21.8.13",
|
|
139
|
+
"i18next-fs-backend": ">=1.1.4",
|
|
140
|
+
"react-i18next": ">=11.18.0"
|
|
120
141
|
}
|
|
121
142
|
}
|