i18next-http-middleware 3.0.2 → 3.0.6
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/CHANGELOG.md +12 -0
- package/README.md +3 -1
- package/cjs/LanguageDetector.js +13 -1
- package/cjs/httpFunctions.js +1 -1
- package/cjs/languageLookups/cookie.js +1 -1
- package/esm/LanguageDetector.js +13 -1
- package/esm/httpFunctions.js +1 -1
- package/esm/languageLookups/cookie.js +1 -1
- package/lib/LanguageDetector.js +9 -1
- package/lib/httpFunctions.js +1 -1
- package/lib/languageLookups/cookie.js +1 -1
- package/package.json +10 -10
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
## [v3.0.6](https://github.com/i18next/i18next-http-middleware/compare/v3.0.5...v3.0.6)
|
|
2
|
+
- ignoreCase option true by default
|
|
3
|
+
|
|
4
|
+
## [v3.0.5](https://github.com/i18next/i18next-http-middleware/compare/v3.0.4...v3.0.5)
|
|
5
|
+
- introduce ignoreCase option
|
|
6
|
+
|
|
7
|
+
## [v3.0.4](https://github.com/i18next/i18next-http-middleware/compare/v3.0.3...v3.0.4)
|
|
8
|
+
- fix language detection algorithm to handle fallbackLng correctly
|
|
9
|
+
|
|
10
|
+
## [v3.0.3](https://github.com/i18next/i18next-http-middleware/compare/v3.0.2...v3.0.3)
|
|
11
|
+
- prevent URIError with cookie language detector
|
|
12
|
+
|
|
1
13
|
## [v3.0.2](https://github.com/i18next/i18next-http-middleware/compare/v3.0.1...v3.0.2)
|
|
2
14
|
- transpile also esm
|
|
3
15
|
|
package/README.md
CHANGED
|
@@ -13,7 +13,7 @@ It's based on the deprecated [i18next-express-middleware](https://github.com/i18
|
|
|
13
13
|
|
|
14
14
|
# Getting started
|
|
15
15
|
|
|
16
|
-
```
|
|
16
|
+
```bash
|
|
17
17
|
# npm package
|
|
18
18
|
$ npm install i18next-http-middleware
|
|
19
19
|
```
|
|
@@ -296,6 +296,8 @@ As with all modules you can either pass the constructor function (class) to the
|
|
|
296
296
|
// cache user language
|
|
297
297
|
caches: false, // ['cookie']
|
|
298
298
|
|
|
299
|
+
ignoreCase: true, // ignore case of detected language
|
|
300
|
+
|
|
299
301
|
// optional expire and domain for set cookie
|
|
300
302
|
cookieExpirationDate: new Date(),
|
|
301
303
|
cookieDomain: 'myDomain',
|
package/cjs/LanguageDetector.js
CHANGED
|
@@ -41,7 +41,8 @@ function getDefaults() {
|
|
|
41
41
|
lookupSession: 'lng',
|
|
42
42
|
lookupFromPathIndex: 0,
|
|
43
43
|
caches: false,
|
|
44
|
-
cookieSameSite: 'strict'
|
|
44
|
+
cookieSameSite: 'strict',
|
|
45
|
+
ignoreCase: true
|
|
45
46
|
});
|
|
46
47
|
}
|
|
47
48
|
|
|
@@ -94,6 +95,17 @@ var LanguageDetector = function () {
|
|
|
94
95
|
|
|
95
96
|
if (_this.services.languageUtils.getBestMatchFromCodes) {
|
|
96
97
|
found = _this.services.languageUtils.getBestMatchFromCodes(detections);
|
|
98
|
+
|
|
99
|
+
if (found) {
|
|
100
|
+
if (_this.options.ignoreCase) {
|
|
101
|
+
if (detections.map(function (d) {
|
|
102
|
+
return d.toLowerCase();
|
|
103
|
+
}).indexOf(found.toLowerCase()) < 0) found = undefined;
|
|
104
|
+
} else {
|
|
105
|
+
if (detections.indexOf(found) < 0) found = undefined;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
97
109
|
if (found) req.i18nextLookupName = detectorName;
|
|
98
110
|
} else {
|
|
99
111
|
found = detections.length > 0 ? detections[0] : null;
|
package/cjs/httpFunctions.js
CHANGED
|
@@ -79,7 +79,7 @@ var getCookies = function getCookies(req) {
|
|
|
79
79
|
var rc = getHeaders(req).cookie;
|
|
80
80
|
rc && rc.split(';').forEach(function (cookie) {
|
|
81
81
|
var parts = cookie.split('=');
|
|
82
|
-
list[parts.shift().trim()] = decodeURI(parts.join('='));
|
|
82
|
+
list[parts.shift().trim()] = decodeURI(encodeURI(parts.join('=')));
|
|
83
83
|
});
|
|
84
84
|
return list;
|
|
85
85
|
}
|
package/esm/LanguageDetector.js
CHANGED
|
@@ -20,7 +20,8 @@ function getDefaults() {
|
|
|
20
20
|
lookupSession: 'lng',
|
|
21
21
|
lookupFromPathIndex: 0,
|
|
22
22
|
caches: false,
|
|
23
|
-
cookieSameSite: 'strict'
|
|
23
|
+
cookieSameSite: 'strict',
|
|
24
|
+
ignoreCase: true
|
|
24
25
|
});
|
|
25
26
|
}
|
|
26
27
|
|
|
@@ -73,6 +74,17 @@ var LanguageDetector = function () {
|
|
|
73
74
|
|
|
74
75
|
if (_this.services.languageUtils.getBestMatchFromCodes) {
|
|
75
76
|
found = _this.services.languageUtils.getBestMatchFromCodes(detections);
|
|
77
|
+
|
|
78
|
+
if (found) {
|
|
79
|
+
if (_this.options.ignoreCase) {
|
|
80
|
+
if (detections.map(function (d) {
|
|
81
|
+
return d.toLowerCase();
|
|
82
|
+
}).indexOf(found.toLowerCase()) < 0) found = undefined;
|
|
83
|
+
} else {
|
|
84
|
+
if (detections.indexOf(found) < 0) found = undefined;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
76
88
|
if (found) req.i18nextLookupName = detectorName;
|
|
77
89
|
} else {
|
|
78
90
|
found = detections.length > 0 ? detections[0] : null;
|
package/esm/httpFunctions.js
CHANGED
|
@@ -51,7 +51,7 @@ export var getCookies = function getCookies(req) {
|
|
|
51
51
|
var rc = getHeaders(req).cookie;
|
|
52
52
|
rc && rc.split(';').forEach(function (cookie) {
|
|
53
53
|
var parts = cookie.split('=');
|
|
54
|
-
list[parts.shift().trim()] = decodeURI(parts.join('='));
|
|
54
|
+
list[parts.shift().trim()] = decodeURI(encodeURI(parts.join('=')));
|
|
55
55
|
});
|
|
56
56
|
return list;
|
|
57
57
|
}
|
package/lib/LanguageDetector.js
CHANGED
|
@@ -19,7 +19,8 @@ function getDefaults () {
|
|
|
19
19
|
// cookieExpirationDate: new Date(),
|
|
20
20
|
// cookieDomain: 'myDomain'
|
|
21
21
|
// cookiePath: '/my/path'
|
|
22
|
-
cookieSameSite: 'strict'
|
|
22
|
+
cookieSameSite: 'strict',
|
|
23
|
+
ignoreCase: true
|
|
23
24
|
})
|
|
24
25
|
}
|
|
25
26
|
|
|
@@ -61,6 +62,13 @@ class LanguageDetector {
|
|
|
61
62
|
|
|
62
63
|
if (this.services.languageUtils.getBestMatchFromCodes) { // new i18next v19.5.0
|
|
63
64
|
found = this.services.languageUtils.getBestMatchFromCodes(detections)
|
|
65
|
+
if (found) {
|
|
66
|
+
if (this.options.ignoreCase) {
|
|
67
|
+
if (detections.map(d => d.toLowerCase()).indexOf(found.toLowerCase()) < 0) found = undefined
|
|
68
|
+
} else {
|
|
69
|
+
if (detections.indexOf(found) < 0) found = undefined
|
|
70
|
+
}
|
|
71
|
+
}
|
|
64
72
|
if (found) req.i18nextLookupName = detectorName
|
|
65
73
|
} else {
|
|
66
74
|
found = detections.length > 0 ? detections[0] : null // a little backward compatibility
|
package/lib/httpFunctions.js
CHANGED
|
@@ -49,7 +49,7 @@ export const getCookies = (req) => {
|
|
|
49
49
|
const rc = getHeaders(req).cookie
|
|
50
50
|
rc && rc.split(';').forEach((cookie) => {
|
|
51
51
|
const parts = cookie.split('=')
|
|
52
|
-
list[parts.shift().trim()] = decodeURI(parts.join('='))
|
|
52
|
+
list[parts.shift().trim()] = decodeURI(encodeURI(parts.join('=')))
|
|
53
53
|
})
|
|
54
54
|
return list
|
|
55
55
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "i18next-http-middleware",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.6",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./cjs/index.js",
|
|
@@ -20,11 +20,11 @@
|
|
|
20
20
|
"module": "./esm/index.js",
|
|
21
21
|
"dependencies": {},
|
|
22
22
|
"devDependencies": {
|
|
23
|
-
"@babel/cli": "7.10.
|
|
24
|
-
"@babel/core": "7.
|
|
25
|
-
"@babel/preset-env": "7.
|
|
23
|
+
"@babel/cli": "7.10.5",
|
|
24
|
+
"@babel/core": "7.11.4",
|
|
25
|
+
"@babel/preset-env": "7.11.0",
|
|
26
26
|
"babel-plugin-add-module-exports": "1.0.2",
|
|
27
|
-
"eslint": "7.
|
|
27
|
+
"eslint": "7.7.0",
|
|
28
28
|
"eslint-config-standard": "14.1.1",
|
|
29
29
|
"eslint-plugin-import": "2.22.0",
|
|
30
30
|
"eslint-plugin-node": "11.1.0",
|
|
@@ -33,11 +33,11 @@
|
|
|
33
33
|
"eslint-plugin-standard": "4.0.1",
|
|
34
34
|
"expect.js": "0.3.1",
|
|
35
35
|
"express": "4.17.1",
|
|
36
|
-
"fastify": "3.
|
|
37
|
-
"i18next": "19.
|
|
38
|
-
"mocha": "8.
|
|
36
|
+
"fastify": "3.3.0",
|
|
37
|
+
"i18next": "19.7.0",
|
|
38
|
+
"mocha": "8.1.3",
|
|
39
39
|
"supertest": "4.0.2",
|
|
40
|
-
"uglify-js": "3.10.
|
|
40
|
+
"uglify-js": "3.10.3"
|
|
41
41
|
},
|
|
42
42
|
"description": "i18next-http-middleware is a middleware to be used with Node.js web frameworks like express or Fastify and also for Deno.",
|
|
43
43
|
"keywords": [
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
"compile": "npm run compile:esm && npm run compile:cjs",
|
|
68
68
|
"build": "npm run compile",
|
|
69
69
|
"test": "npm run lint && npm run build && mocha test -R spec --exit --experimental-modules",
|
|
70
|
-
"test:deno": "deno test test/deno/*.js --allow-net",
|
|
70
|
+
"test:deno": "deno test test/deno/*.js --allow-net --no-check",
|
|
71
71
|
"preversion": "npm run test && npm run build && git push",
|
|
72
72
|
"postversion": "git push && git push --tags"
|
|
73
73
|
}
|