i18next-http-middleware 3.10.0 → 3.10.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/cjs/index.js CHANGED
@@ -132,7 +132,7 @@ function handle(i18next) {
132
132
  i18next.services.languageDetector.cacheUserLanguage(req, res, lng);
133
133
  }
134
134
  if (!req.lng) return next();
135
- i18next.loadLanguages(req.lng, function () {
135
+ i18n.loadLanguages(req.lng, function () {
136
136
  return next();
137
137
  });
138
138
  };
@@ -253,17 +253,16 @@ function getResourcesHandler(i18next) {
253
253
  }
254
254
  languages = languages.filter(utils.isSafeLangIdentifier);
255
255
  namespaces = namespaces.filter(utils.isSafeNsIdentifier);
256
- namespaces.forEach(function (ns) {
257
- if (i18next.options.ns && i18next.options.ns.indexOf(ns) < 0) {
258
- i18next.options.ns.push(ns);
259
- }
260
- });
261
256
  var loaded = false;
262
257
  var onLoaded;
263
258
  i18next.services.backendConnector.load(languages, namespaces, function () {
264
259
  languages.forEach(function (lng) {
265
260
  namespaces.forEach(function (ns) {
266
- utils.setPath(resources, [lng, ns], i18next.getResourceBundle(lng, ns));
261
+ var bundle = i18next.getResourceBundle(lng, ns);
262
+ if (bundle && i18next.options.ns && i18next.options.ns.indexOf(ns) < 0) {
263
+ i18next.options.ns.push(ns);
264
+ }
265
+ utils.setPath(resources, [lng, ns], bundle);
267
266
  });
268
267
  });
269
268
  loaded = true;
package/esm/index.js CHANGED
@@ -115,7 +115,7 @@ export function handle(i18next) {
115
115
  i18next.services.languageDetector.cacheUserLanguage(req, res, lng);
116
116
  }
117
117
  if (!req.lng) return next();
118
- i18next.loadLanguages(req.lng, function () {
118
+ i18n.loadLanguages(req.lng, function () {
119
119
  return next();
120
120
  });
121
121
  };
@@ -236,17 +236,16 @@ export function getResourcesHandler(i18next) {
236
236
  }
237
237
  languages = languages.filter(utils.isSafeLangIdentifier);
238
238
  namespaces = namespaces.filter(utils.isSafeNsIdentifier);
239
- namespaces.forEach(function (ns) {
240
- if (i18next.options.ns && i18next.options.ns.indexOf(ns) < 0) {
241
- i18next.options.ns.push(ns);
242
- }
243
- });
244
239
  var loaded = false;
245
240
  var onLoaded;
246
241
  i18next.services.backendConnector.load(languages, namespaces, function () {
247
242
  languages.forEach(function (lng) {
248
243
  namespaces.forEach(function (ns) {
249
- utils.setPath(resources, [lng, ns], i18next.getResourceBundle(lng, ns));
244
+ var bundle = i18next.getResourceBundle(lng, ns);
245
+ if (bundle && i18next.options.ns && i18next.options.ns.indexOf(ns) < 0) {
246
+ i18next.options.ns.push(ns);
247
+ }
248
+ utils.setPath(resources, [lng, ns], bundle);
250
249
  });
251
250
  });
252
251
  loaded = true;
package/lib/index.js CHANGED
@@ -127,9 +127,11 @@ export function handle (i18next, options = {}) {
127
127
  if (i18next.services.languageDetector) {
128
128
  i18next.services.languageDetector.cacheUserLanguage(req, res, lng)
129
129
  }
130
- // load resources
130
+ // load resources: through the request's clone, as loadLanguages() adds
131
+ // the language to options.preload, and every request on the shared
132
+ // instance pays for the length of that list until the process restarts
131
133
  if (!req.lng) return next()
132
- i18next.loadLanguages(req.lng, () => next())
134
+ i18n.loadLanguages(req.lng, () => next())
133
135
  }
134
136
  }
135
137
 
@@ -265,23 +267,19 @@ export function getResourcesHandler (i18next, options = {}) {
265
267
  languages = languages.filter(utils.isSafeLangIdentifier)
266
268
  namespaces = namespaces.filter(utils.isSafeNsIdentifier)
267
269
 
268
- // extend ns
269
- namespaces.forEach(ns => {
270
- if (i18next.options.ns && i18next.options.ns.indexOf(ns) < 0) {
271
- i18next.options.ns.push(ns)
272
- }
273
- })
274
-
275
270
  let loaded = false
276
271
  let onLoaded
277
272
  i18next.services.backendConnector.load(languages, namespaces, function () {
278
273
  languages.forEach(lng => {
279
274
  namespaces.forEach(ns => {
280
- utils.setPath(
281
- resources,
282
- [lng, ns],
283
- i18next.getResourceBundle(lng, ns)
284
- )
275
+ const bundle = i18next.getResourceBundle(lng, ns)
276
+ // extend ns only with a namespace the backend has: every request
277
+ // pays for the length of this shared list, and a made-up ns from
278
+ // the request would stay in it until the process restarts
279
+ if (bundle && i18next.options.ns && i18next.options.ns.indexOf(ns) < 0) {
280
+ i18next.options.ns.push(ns)
281
+ }
282
+ utils.setPath(resources, [lng, ns], bundle)
285
283
  })
286
284
  })
287
285
  loaded = true
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "i18next-http-middleware",
3
- "version": "3.10.0",
3
+ "version": "3.10.1",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "./cjs/index.js",