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 0.0.17 to 0.1.0

4

lib/index.js

@@ -42,2 +42,6 @@ 'use strict';

if (req.i18nextLookupName === 'path' && options.removeLngFromUrl) {
req.url = utils.removeLngFromUrl(req.url, i18next.services.languageDetector.options.lookupFromPathIndex);
}
// assert t function returns always translation

@@ -44,0 +48,0 @@ // in given lng inside this request

23

lib/LanguageDetector.js

@@ -96,18 +96,17 @@ 'use strict';

var detected = [];
var found = undefined;
detectionOrder.forEach(function (detectorName) {
if (_this.detectors[detectorName]) {
var lookup = _this.detectors[detectorName].lookup(req, res, _this.options);
if (lookup && typeof lookup === 'string') lookup = [lookup];
if (lookup) detected = detected.concat(lookup);
if (found || !_this.detectors[detectorName]) return;
var lng = _this.detectors[detectorName].lookup(req, res, _this.options);
if (lng && typeof lng === 'string') {
var cleanedLng = _this.services.languageUtils.formatLanguageCode(lng);
if (_this.services.languageUtils.isWhitelisted(cleanedLng)) {
found = cleanedLng;
req.i18nextLookupName = detectorName;
};
}
});
var found = undefined;
detected.forEach(function (lng) {
if (found) return;
var cleanedLng = _this.services.languageUtils.formatLanguageCode(lng);
if (_this.services.languageUtils.isWhitelisted(cleanedLng)) found = cleanedLng;
});
return found || this.allOptions.fallbackLng && this.allOptions.fallbackLng[0];

@@ -114,0 +113,0 @@ }

@@ -9,2 +9,3 @@ 'use strict';

exports.extend = extend;
exports.removeLngFromUrl = removeLngFromUrl;

@@ -52,2 +53,20 @@ function setPath(object, path, newValue) {

return obj;
}
function removeLngFromUrl(url, lookupFromPathIndex) {
var first = '';
var pos = lookupFromPathIndex;
if (url[0] === '/') {
pos++;
first = '/';
}
// Build new url
var parts = url.split('/');
parts.splice(pos, 1);
url = parts.join('/');
if (url[0] !== '/') url = first + url;
return url;
}
{
"name": "i18next-express-middleware",
"version": "0.0.17",
"version": "0.1.0",
"description": "express middleware for i18next",

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

@@ -24,3 +24,6 @@ # Introduction

var app = express();
app.use(middleware.handle(i18next));
app.use(middleware.handle(i18next, {
ignoreRoutes: ["/foo"],
removeLngFromUrl: false
}));

@@ -27,0 +30,0 @@

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