i18next-express-middleware
Advanced tools
Comparing version 0.0.17 to 0.1.0
@@ -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 |
@@ -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 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
22039
413
168