Socket
Socket
Sign inDemoInstall

i18next-express-middleware

Package Overview
Dependencies
Maintainers
1
Versions
58
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

i18next-express-middleware - npm Package Compare versions

Comparing version 1.4.0 to 1.4.1

4

CHANGELOG.md

@@ -0,1 +1,5 @@

### 1.4.1
- Update locals on languageChanged [PR163](https://github.com/i18next/i18next-express-middleware/pull/163)
### 1.4.0

@@ -2,0 +6,0 @@

@@ -27,3 +27,3 @@ 'use strict';

function handle(i18next) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];

@@ -40,6 +40,14 @@ return function i18nextMiddleware(req, res, next) {

req.language = req.locale = req.lng = lng;
if (res.locals) {
res.locals.language = lng;
res.locals.languageDir = i18next.dir(lng);
}
if (!res.headersSent) {
res.set('Content-Language', lng);
}
req.languages = i18next.services.languageUtils.toResolveHierarchy(lng);
if (i18next.services.languageDetector) {

@@ -46,0 +54,0 @@ i18next.services.languageDetector.cacheUserLanguage(req, res, lng);

8

lib/LanguageDetector.js

@@ -56,4 +56,4 @@ 'use strict';

function LanguageDetector(services) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var allOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
var allOptions = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];

@@ -71,4 +71,4 @@ _classCallCheck(this, LanguageDetector);

value: function init(services) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var allOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
var allOptions = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];

@@ -75,0 +75,0 @@ this.services = services;

@@ -31,3 +31,3 @@ 'use strict';

cacheUserLanguage: function cacheUserLanguage(req, res, lng) {
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
var options = arguments.length <= 3 || arguments[3] === undefined ? {} : arguments[3];

@@ -34,0 +34,0 @@ if (options.lookupCookie && req !== 'undefined' && !(res._headerSent || res.headersSent)) {

@@ -20,33 +20,35 @@ 'use strict';

if (acceptLanguage) {
var lngs = [],
i = void 0;
(function () {
var lngs = [],
i = void 0;
// associate language tags by their 'q' value (between 1 and 0)
acceptLanguage.split(',').forEach(function (l) {
var parts = l.split(';'); // 'en-GB;q=0.8' -> ['en-GB', 'q=0.8']
// associate language tags by their 'q' value (between 1 and 0)
acceptLanguage.split(',').forEach(function (l) {
var parts = l.split(';'); // 'en-GB;q=0.8' -> ['en-GB', 'q=0.8']
// get the language tag qvalue: 'q=0.8' -> 0.8
var qvalue = 1; // default qvalue
// get the language tag qvalue: 'q=0.8' -> 0.8
var qvalue = 1; // default qvalue
for (i = 0; i < parts.length; i++) {
var part = parts[i].split('=');
if (part[0] === 'q' && !isNaN(part[1])) {
qvalue = Number(part[1]);
break;
for (i = 0; i < parts.length; i++) {
var part = parts[i].split('=');
if (part[0] === 'q' && !isNaN(part[1])) {
qvalue = Number(part[1]);
break;
}
}
}
// add the tag and primary subtag to the qvalue associations
lngs.push({ lng: parts[0], q: qvalue });
});
// add the tag and primary subtag to the qvalue associations
lngs.push({ lng: parts[0], q: qvalue });
});
lngs.sort(function (a, b) {
return b.q - a.q;
});
lngs.sort(function (a, b) {
return b.q - a.q;
});
for (i = 0; i < lngs.length; i++) {
locales.push(lngs[i].lng);
}
for (i = 0; i < lngs.length; i++) {
locales.push(lngs[i].lng);
}
if (locales.length) found = locales;
if (locales.length) found = locales;
})();
}

@@ -53,0 +55,0 @@ }

@@ -7,3 +7,3 @@ 'use strict';

var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; };

@@ -23,3 +23,3 @@ exports.default = {

cacheUserLanguage: function cacheUserLanguage(req, res, lng) {
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
var options = arguments.length <= 3 || arguments[3] === undefined ? {} : arguments[3];

@@ -26,0 +26,0 @@ if (options.lookupSession && req && req.session) {

{
"name": "i18next-express-middleware",
"version": "1.4.0",
"version": "1.4.1",
"description": "express middleware for i18next",

@@ -5,0 +5,0 @@ "main": "./lib/index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc