i18next-express-middleware
Advanced tools
Comparing version 1.5.0 to 1.6.0
@@ -0,1 +1,5 @@ | ||
### 1.6.0 | ||
- Handle spaces in Accept-Language header [169](https://github.com/i18next/i18next-express-middleware/pull/169) | ||
### 1.5.0 | ||
@@ -2,0 +6,0 @@ |
@@ -21,23 +21,18 @@ 'use strict'; | ||
var lngs = [], | ||
i = void 0; | ||
i = void 0, | ||
m = void 0; | ||
var rgx = /(([a-z]{2})-?([A-Z]{2})?)\s*;?\s*(q=([0-9.]+))?/g; | ||
// 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 | ||
for (i = 0; i < parts.length; i++) { | ||
var part = parts[i].split('='); | ||
if (part[0] === 'q' && !isNaN(part[1])) { | ||
qvalue = Number(part[1]); | ||
break; | ||
do { | ||
m = rgx.exec(acceptLanguage); | ||
if (m) { | ||
var lng = m[1], | ||
weight = m[5] || '1', | ||
q = Number(weight); | ||
if (lng && !isNaN(q)) { | ||
lngs.push({ lng: lng, q: q }); | ||
} | ||
} | ||
} while (m); | ||
// add the tag and primary subtag to the qvalue associations | ||
lngs.push({ lng: parts[0], q: qvalue }); | ||
}); | ||
lngs.sort(function (a, b) { | ||
@@ -44,0 +39,0 @@ return b.q - a.q; |
{ | ||
"name": "i18next-express-middleware", | ||
"version": "1.5.0", | ||
"version": "1.6.0", | ||
"description": "express middleware for i18next", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
@@ -51,3 +51,3 @@ # Introduction | ||
```js | ||
// missing keys | ||
// missing keys; make sure the body is parsed (i.e. with [body-parser](https://github.com/expressjs/body-parser#bodyparserjsonoptions)) | ||
app.post("/locales/add/:lng/:ns", middleware.missingKeyHandler(i18next)); | ||
@@ -54,0 +54,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
28525
471