next-i18next 13.1.5 → 13.1.6
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
|
@@ -216,6 +216,8 @@ module.exports = {
|
|
|
216
216
|
|
|
217
217
|
Be aware that using `fallbackLng` and `nonExplicitSupportedLngs` can easily increase the initial size of the page.
|
|
218
218
|
|
|
219
|
+
fyi: Setting `fallbackLng` to `false` will NOT serialize your fallback language (usually `defaultLocale`). This will decrease the size of your initial page load.
|
|
220
|
+
|
|
219
221
|
### 6. Advanced configuration
|
|
220
222
|
|
|
221
223
|
#### Passing other config options
|
|
@@ -398,6 +400,18 @@ But there's a way to workaround that with the help of [next-language-detector](h
|
|
|
398
400
|
Check out [this blog post](https://locize.com/blog/next-i18n-static/) and [this example project](./examples/ssg/).
|
|
399
401
|
[](https://locize.com/blog/next-i18n-static/)
|
|
400
402
|
|
|
403
|
+
|
|
404
|
+
### Translate in child components
|
|
405
|
+
|
|
406
|
+
You have multiple ways to use the t function in your child component:
|
|
407
|
+
|
|
408
|
+
1. Pass the `t` function via props down to the children
|
|
409
|
+
2. Pass the translated text via props down to the children, like in this example: https://github.com/i18next/next-i18next/blob/master/examples/simple/components/Header.tsx#L12
|
|
410
|
+
3. Use the [`useTranslation`](https://react.i18next.com/latest/usetranslation-hook) function, like in this example: https://github.com/i18next/next-i18next/blob/e6b5085b5e92004afa9516bd444b19b2c8cf5758/examples/simple/components/Footer.tsx#L6
|
|
411
|
+
4. Use the [`withTranslation`](https://react.i18next.com/latest/withtranslation-hoc) function
|
|
412
|
+
|
|
413
|
+
*And in general, you always needs to be sure serverSideTranslations contains all namespaces you need in the tree.*
|
|
414
|
+
|
|
401
415
|
## Contributors
|
|
402
416
|
|
|
403
417
|
Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds/all-contributors#emoji-key)):
|
|
@@ -22,12 +22,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
22
22
|
exports.createConfig = void 0;
|
|
23
23
|
require("core-js/modules/es.array.filter.js");
|
|
24
24
|
require("core-js/modules/es.object.to-string.js");
|
|
25
|
+
require("core-js/modules/es.array.concat.js");
|
|
25
26
|
require("core-js/modules/es.array.reduce.js");
|
|
26
27
|
require("core-js/modules/es.array.includes.js");
|
|
27
28
|
require("core-js/modules/es.string.includes.js");
|
|
28
29
|
require("core-js/modules/es.array.is-array.js");
|
|
29
30
|
require("core-js/modules/es.object.entries.js");
|
|
30
|
-
require("core-js/modules/es.array.concat.js");
|
|
31
31
|
require("core-js/modules/es.array.some.js");
|
|
32
32
|
require("core-js/modules/es.regexp.exec.js");
|
|
33
33
|
require("core-js/modules/es.string.replace.js");
|
|
@@ -51,7 +51,7 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
|
|
|
51
51
|
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; }
|
|
52
52
|
var deepMergeObjects = ['backend', 'detection'];
|
|
53
53
|
var createConfig = function createConfig(userConfig) {
|
|
54
|
-
var _userConfig$use;
|
|
54
|
+
var _userConfig$interpola, _userConfig$interpola2, _userConfig$use;
|
|
55
55
|
if (typeof (userConfig === null || userConfig === void 0 ? void 0 : userConfig.lng) !== 'string') {
|
|
56
56
|
throw new Error('config.lng was not passed into createConfig');
|
|
57
57
|
}
|
|
@@ -68,7 +68,6 @@ var createConfig = function createConfig(userConfig) {
|
|
|
68
68
|
lng = combinedConfig.lng,
|
|
69
69
|
localeExtension = combinedConfig.localeExtension,
|
|
70
70
|
localePath = combinedConfig.localePath,
|
|
71
|
-
localeStructure = combinedConfig.localeStructure,
|
|
72
71
|
nonExplicitSupportedLngs = combinedConfig.nonExplicitSupportedLngs;
|
|
73
72
|
var locales = combinedConfig.locales.filter(function (l) {
|
|
74
73
|
return l !== 'default';
|
|
@@ -88,7 +87,15 @@ var createConfig = function createConfig(userConfig) {
|
|
|
88
87
|
combinedConfig.fallbackLng = _locales[0];
|
|
89
88
|
}
|
|
90
89
|
}
|
|
91
|
-
var
|
|
90
|
+
var userPrefix = userConfig === null || userConfig === void 0 ? void 0 : (_userConfig$interpola = userConfig.interpolation) === null || _userConfig$interpola === void 0 ? void 0 : _userConfig$interpola.prefix;
|
|
91
|
+
var userSuffix = userConfig === null || userConfig === void 0 ? void 0 : (_userConfig$interpola2 = userConfig.interpolation) === null || _userConfig$interpola2 === void 0 ? void 0 : _userConfig$interpola2.suffix;
|
|
92
|
+
var prefix = userPrefix !== null && userPrefix !== void 0 ? userPrefix : '{{';
|
|
93
|
+
var suffix = userSuffix !== null && userSuffix !== void 0 ? userSuffix : '}}';
|
|
94
|
+
if (typeof (userConfig === null || userConfig === void 0 ? void 0 : userConfig.localeStructure) !== 'string' && (userPrefix || userSuffix)) {
|
|
95
|
+
combinedConfig.localeStructure = "".concat(prefix, "lng").concat(suffix, "/").concat(prefix, "ns").concat(suffix);
|
|
96
|
+
}
|
|
97
|
+
var fallbackLng = combinedConfig.fallbackLng,
|
|
98
|
+
localeStructure = combinedConfig.localeStructure;
|
|
92
99
|
if (nonExplicitSupportedLngs) {
|
|
93
100
|
var createFallbackObject = function createFallbackObject(acc, l) {
|
|
94
101
|
var _l$split = l.split('-'),
|
|
@@ -136,9 +143,6 @@ var createConfig = function createConfig(userConfig) {
|
|
|
136
143
|
//
|
|
137
144
|
if (typeof defaultNS === 'string' && typeof lng !== 'undefined') {
|
|
138
145
|
if (typeof localePath === 'string') {
|
|
139
|
-
var _userConfig$interpola, _userConfig$interpola2, _userConfig$interpola3, _userConfig$interpola4;
|
|
140
|
-
var prefix = (_userConfig$interpola = userConfig === null || userConfig === void 0 ? void 0 : (_userConfig$interpola2 = userConfig.interpolation) === null || _userConfig$interpola2 === void 0 ? void 0 : _userConfig$interpola2.prefix) !== null && _userConfig$interpola !== void 0 ? _userConfig$interpola : '{{';
|
|
141
|
-
var suffix = (_userConfig$interpola3 = userConfig === null || userConfig === void 0 ? void 0 : (_userConfig$interpola4 = userConfig.interpolation) === null || _userConfig$interpola4 === void 0 ? void 0 : _userConfig$interpola4.suffix) !== null && _userConfig$interpola3 !== void 0 ? _userConfig$interpola3 : '}}';
|
|
142
146
|
var defaultLocaleStructure = localeStructure.replace("".concat(prefix, "lng").concat(suffix), lng).replace("".concat(prefix, "ns").concat(suffix), defaultNS);
|
|
143
147
|
var defaultFile = "/".concat(defaultLocaleStructure, ".").concat(localeExtension);
|
|
144
148
|
var defaultNSPath = path.join(localePath, defaultFile);
|
|
@@ -191,7 +195,6 @@ var createConfig = function createConfig(userConfig) {
|
|
|
191
195
|
// Set server side preload (namespaces)
|
|
192
196
|
//
|
|
193
197
|
if (!combinedConfig.ns && typeof lng !== 'undefined') {
|
|
194
|
-
var _userConfig$interpola5, _userConfig$interpola6, _userConfig$interpola7, _userConfig$interpola8;
|
|
195
198
|
if (typeof localePath === 'function') {
|
|
196
199
|
throw new Error('Must provide all namespaces in ns option if using a function as localePath');
|
|
197
200
|
}
|
|
@@ -230,9 +233,7 @@ var createConfig = function createConfig(userConfig) {
|
|
|
230
233
|
}
|
|
231
234
|
return (0, _utils.unique)(allNamespaces);
|
|
232
235
|
};
|
|
233
|
-
|
|
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
|
+
if (localeStructure.indexOf("".concat(prefix, "lng").concat(suffix)) > localeStructure.indexOf("".concat(prefix, "ns").concat(suffix))) {
|
|
236
237
|
throw new Error('Must provide all namespaces in ns option if using a localeStructure that is not namespace-listable like lng/ns');
|
|
237
238
|
}
|
|
238
239
|
combinedConfig.ns = getNamespaces((0, _utils.unique)([lng].concat((0, _toConsumableArray2["default"])((0, _utils.getFallbackForLng)(lng, combinedConfig.fallbackLng)))));
|
|
@@ -28,7 +28,6 @@ export const createConfig = userConfig => {
|
|
|
28
28
|
lng,
|
|
29
29
|
localeExtension,
|
|
30
30
|
localePath,
|
|
31
|
-
localeStructure,
|
|
32
31
|
nonExplicitSupportedLngs
|
|
33
32
|
} = combinedConfig;
|
|
34
33
|
const locales = combinedConfig.locales.filter(l => l !== 'default');
|
|
@@ -44,8 +43,16 @@ export const createConfig = userConfig => {
|
|
|
44
43
|
combinedConfig.fallbackLng = combinedConfig.defaultLocale;
|
|
45
44
|
if (combinedConfig.fallbackLng === 'default') [combinedConfig.fallbackLng] = locales;
|
|
46
45
|
}
|
|
46
|
+
const userPrefix = userConfig?.interpolation?.prefix;
|
|
47
|
+
const userSuffix = userConfig?.interpolation?.suffix;
|
|
48
|
+
const prefix = userPrefix ?? '{{';
|
|
49
|
+
const suffix = userSuffix ?? '}}';
|
|
50
|
+
if (typeof userConfig?.localeStructure !== 'string' && (userPrefix || userSuffix)) {
|
|
51
|
+
combinedConfig.localeStructure = `${prefix}lng${suffix}/${prefix}ns${suffix}`;
|
|
52
|
+
}
|
|
47
53
|
const {
|
|
48
|
-
fallbackLng
|
|
54
|
+
fallbackLng,
|
|
55
|
+
localeStructure
|
|
49
56
|
} = combinedConfig;
|
|
50
57
|
if (nonExplicitSupportedLngs) {
|
|
51
58
|
const createFallbackObject = (acc, l) => {
|
|
@@ -83,8 +90,6 @@ export const createConfig = userConfig => {
|
|
|
83
90
|
//
|
|
84
91
|
if (typeof defaultNS === 'string' && typeof lng !== 'undefined') {
|
|
85
92
|
if (typeof localePath === 'string') {
|
|
86
|
-
const prefix = userConfig?.interpolation?.prefix ?? '{{';
|
|
87
|
-
const suffix = userConfig?.interpolation?.suffix ?? '}}';
|
|
88
93
|
const defaultLocaleStructure = localeStructure.replace(`${prefix}lng${suffix}`, lng).replace(`${prefix}ns${suffix}`, defaultNS);
|
|
89
94
|
const defaultFile = `/${defaultLocaleStructure}.${localeExtension}`;
|
|
90
95
|
const defaultNSPath = path.join(localePath, defaultFile);
|
|
@@ -158,8 +163,6 @@ export const createConfig = userConfig => {
|
|
|
158
163
|
}
|
|
159
164
|
return unique(allNamespaces);
|
|
160
165
|
};
|
|
161
|
-
const prefix = userConfig?.interpolation?.prefix ?? '{{';
|
|
162
|
-
const suffix = userConfig?.interpolation?.suffix ?? '}}';
|
|
163
166
|
if (localeStructure.indexOf(`${prefix}lng${suffix}`) > localeStructure.indexOf(`${prefix}ns${suffix}`)) {
|
|
164
167
|
throw new Error('Must provide all namespaces in ns option if using a localeStructure that is not namespace-listable like lng/ns');
|
|
165
168
|
}
|
|
@@ -14,7 +14,7 @@ import { defaultConfig } from './defaultConfig';
|
|
|
14
14
|
import { getFallbackForLng, unique } from '../utils';
|
|
15
15
|
var deepMergeObjects = ['backend', 'detection'];
|
|
16
16
|
export var createConfig = function createConfig(userConfig) {
|
|
17
|
-
var _userConfig$use;
|
|
17
|
+
var _userConfig$interpola, _userConfig$interpola2, _userConfig$use;
|
|
18
18
|
if (typeof (userConfig === null || userConfig === void 0 ? void 0 : userConfig.lng) !== 'string') {
|
|
19
19
|
throw new Error('config.lng was not passed into createConfig');
|
|
20
20
|
}
|
|
@@ -31,7 +31,6 @@ export var createConfig = function createConfig(userConfig) {
|
|
|
31
31
|
lng = combinedConfig.lng,
|
|
32
32
|
localeExtension = combinedConfig.localeExtension,
|
|
33
33
|
localePath = combinedConfig.localePath,
|
|
34
|
-
localeStructure = combinedConfig.localeStructure,
|
|
35
34
|
nonExplicitSupportedLngs = combinedConfig.nonExplicitSupportedLngs;
|
|
36
35
|
var locales = combinedConfig.locales.filter(function (l) {
|
|
37
36
|
return l !== 'default';
|
|
@@ -51,7 +50,15 @@ export var createConfig = function createConfig(userConfig) {
|
|
|
51
50
|
combinedConfig.fallbackLng = _locales[0];
|
|
52
51
|
}
|
|
53
52
|
}
|
|
54
|
-
var
|
|
53
|
+
var userPrefix = userConfig === null || userConfig === void 0 ? void 0 : (_userConfig$interpola = userConfig.interpolation) === null || _userConfig$interpola === void 0 ? void 0 : _userConfig$interpola.prefix;
|
|
54
|
+
var userSuffix = userConfig === null || userConfig === void 0 ? void 0 : (_userConfig$interpola2 = userConfig.interpolation) === null || _userConfig$interpola2 === void 0 ? void 0 : _userConfig$interpola2.suffix;
|
|
55
|
+
var prefix = userPrefix !== null && userPrefix !== void 0 ? userPrefix : '{{';
|
|
56
|
+
var suffix = userSuffix !== null && userSuffix !== void 0 ? userSuffix : '}}';
|
|
57
|
+
if (typeof (userConfig === null || userConfig === void 0 ? void 0 : userConfig.localeStructure) !== 'string' && (userPrefix || userSuffix)) {
|
|
58
|
+
combinedConfig.localeStructure = "".concat(prefix, "lng").concat(suffix, "/").concat(prefix, "ns").concat(suffix);
|
|
59
|
+
}
|
|
60
|
+
var fallbackLng = combinedConfig.fallbackLng,
|
|
61
|
+
localeStructure = combinedConfig.localeStructure;
|
|
55
62
|
if (nonExplicitSupportedLngs) {
|
|
56
63
|
var createFallbackObject = function createFallbackObject(acc, l) {
|
|
57
64
|
var _l$split = l.split('-'),
|
|
@@ -99,9 +106,6 @@ export var createConfig = function createConfig(userConfig) {
|
|
|
99
106
|
//
|
|
100
107
|
if (typeof defaultNS === 'string' && typeof lng !== 'undefined') {
|
|
101
108
|
if (typeof localePath === 'string') {
|
|
102
|
-
var _userConfig$interpola, _userConfig$interpola2, _userConfig$interpola3, _userConfig$interpola4;
|
|
103
|
-
var prefix = (_userConfig$interpola = userConfig === null || userConfig === void 0 ? void 0 : (_userConfig$interpola2 = userConfig.interpolation) === null || _userConfig$interpola2 === void 0 ? void 0 : _userConfig$interpola2.prefix) !== null && _userConfig$interpola !== void 0 ? _userConfig$interpola : '{{';
|
|
104
|
-
var suffix = (_userConfig$interpola3 = userConfig === null || userConfig === void 0 ? void 0 : (_userConfig$interpola4 = userConfig.interpolation) === null || _userConfig$interpola4 === void 0 ? void 0 : _userConfig$interpola4.suffix) !== null && _userConfig$interpola3 !== void 0 ? _userConfig$interpola3 : '}}';
|
|
105
109
|
var defaultLocaleStructure = localeStructure.replace("".concat(prefix, "lng").concat(suffix), lng).replace("".concat(prefix, "ns").concat(suffix), defaultNS);
|
|
106
110
|
var defaultFile = "/".concat(defaultLocaleStructure, ".").concat(localeExtension);
|
|
107
111
|
var defaultNSPath = path.join(localePath, defaultFile);
|
|
@@ -154,7 +158,6 @@ export var createConfig = function createConfig(userConfig) {
|
|
|
154
158
|
// Set server side preload (namespaces)
|
|
155
159
|
//
|
|
156
160
|
if (!combinedConfig.ns && typeof lng !== 'undefined') {
|
|
157
|
-
var _userConfig$interpola5, _userConfig$interpola6, _userConfig$interpola7, _userConfig$interpola8;
|
|
158
161
|
if (typeof localePath === 'function') {
|
|
159
162
|
throw new Error('Must provide all namespaces in ns option if using a function as localePath');
|
|
160
163
|
}
|
|
@@ -193,9 +196,7 @@ export var createConfig = function createConfig(userConfig) {
|
|
|
193
196
|
}
|
|
194
197
|
return unique(allNamespaces);
|
|
195
198
|
};
|
|
196
|
-
|
|
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
|
+
if (localeStructure.indexOf("".concat(prefix, "lng").concat(suffix)) > localeStructure.indexOf("".concat(prefix, "ns").concat(suffix))) {
|
|
199
200
|
throw new Error('Must provide all namespaces in ns option if using a localeStructure that is not namespace-listable like lng/ns');
|
|
200
201
|
}
|
|
201
202
|
combinedConfig.ns = getNamespaces(unique([lng].concat(_toConsumableArray(getFallbackForLng(lng, combinedConfig.fallbackLng)))));
|