i18next-http-middleware 3.4.1 → 3.6.0
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/README.md +5 -1
- package/cjs/LanguageDetector.js +14 -3
- package/cjs/index.d.ts +5 -0
- package/cjs/index.js +2 -2
- package/esm/LanguageDetector.js +12 -1
- package/esm/index.d.mts +1 -0
- package/esm/index.d.ts +5 -0
- package/index.d.mts +1 -0
- package/index.d.ts +5 -0
- package/lib/LanguageDetector.js +8 -1
- package/package.json +15 -15
package/README.md
CHANGED
|
@@ -398,7 +398,11 @@ As with all modules you can either pass the constructor function (class) to the
|
|
|
398
398
|
cookieDomain: 'myDomain',
|
|
399
399
|
cookiePath: '/my/path',
|
|
400
400
|
cookieSecure: true, // if need secure cookie
|
|
401
|
-
cookieSameSite: 'strict' // 'strict', 'lax' or 'none'
|
|
401
|
+
cookieSameSite: 'strict', // 'strict', 'lax' or 'none'
|
|
402
|
+
|
|
403
|
+
// optional conversion function used to modify the detected language code
|
|
404
|
+
convertDetectedLanguage: 'Iso15897',
|
|
405
|
+
convertDetectedLanguage: (lng) => lng.replace('-', '_')
|
|
402
406
|
}
|
|
403
407
|
```
|
|
404
408
|
|
package/cjs/LanguageDetector.js
CHANGED
|
@@ -12,8 +12,8 @@ var _header = _interopRequireDefault(require("./languageLookups/header.js"));
|
|
|
12
12
|
var _session = _interopRequireDefault(require("./languageLookups/session.js"));
|
|
13
13
|
var _httpFunctions = require("./httpFunctions.js");
|
|
14
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
-
function _getRequireWildcardCache(
|
|
16
|
-
function _interopRequireWildcard(
|
|
15
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
16
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
17
17
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
18
18
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
19
19
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
@@ -29,7 +29,10 @@ function getDefaults() {
|
|
|
29
29
|
lookupFromPathIndex: 0,
|
|
30
30
|
caches: false,
|
|
31
31
|
cookieSameSite: 'strict',
|
|
32
|
-
ignoreCase: true
|
|
32
|
+
ignoreCase: true,
|
|
33
|
+
convertDetectedLanguage: function convertDetectedLanguage(l) {
|
|
34
|
+
return l;
|
|
35
|
+
}
|
|
33
36
|
});
|
|
34
37
|
}
|
|
35
38
|
var LanguageDetector = function () {
|
|
@@ -49,6 +52,11 @@ var LanguageDetector = function () {
|
|
|
49
52
|
this.services = services;
|
|
50
53
|
this.options = utils.defaults(options, this.options || {}, getDefaults());
|
|
51
54
|
this.allOptions = allOptions;
|
|
55
|
+
if (typeof this.options.convertDetectedLanguage === 'string' && this.options.convertDetectedLanguage.indexOf('15897') > -1) {
|
|
56
|
+
this.options.convertDetectedLanguage = function (l) {
|
|
57
|
+
return l.replace('-', '_');
|
|
58
|
+
};
|
|
59
|
+
}
|
|
52
60
|
this.addDetector(_cookie.default);
|
|
53
61
|
this.addDetector(_querystring.default);
|
|
54
62
|
this.addDetector(_path.default);
|
|
@@ -75,6 +83,9 @@ var LanguageDetector = function () {
|
|
|
75
83
|
detections = detections.filter(function (d) {
|
|
76
84
|
return d !== undefined && d !== null;
|
|
77
85
|
});
|
|
86
|
+
detections = detections.map(function (d) {
|
|
87
|
+
return _this.options.convertDetectedLanguage(d);
|
|
88
|
+
});
|
|
78
89
|
if (_this.services.languageUtils.getBestMatchFromCodes) {
|
|
79
90
|
found = _this.services.languageUtils.getBestMatchFromCodes(detections);
|
|
80
91
|
if (found) {
|
package/cjs/index.d.ts
CHANGED
|
@@ -115,6 +115,11 @@ interface LanguageDetectorOptions {
|
|
|
115
115
|
caches?: LanguageDetectorCaches;
|
|
116
116
|
cookieExpirationDate?: Date;
|
|
117
117
|
cookieDomain?: string;
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* optional conversion function to use to modify the detected language code
|
|
121
|
+
*/
|
|
122
|
+
convertDetectedLanguage?: 'Iso15897' | ((lng: string) => string);
|
|
118
123
|
}
|
|
119
124
|
interface LanguageDetectorAllOptions {
|
|
120
125
|
fallbackLng: boolean | string | string[];
|
package/cjs/index.js
CHANGED
|
@@ -17,8 +17,8 @@ var utils = _interopRequireWildcard(require("./utils.js"));
|
|
|
17
17
|
var _LanguageDetector = _interopRequireDefault(require("./LanguageDetector.js"));
|
|
18
18
|
var _httpFunctions = require("./httpFunctions.js");
|
|
19
19
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
20
|
-
function _getRequireWildcardCache(
|
|
21
|
-
function _interopRequireWildcard(
|
|
20
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
21
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
22
22
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
23
23
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
24
24
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
package/esm/LanguageDetector.js
CHANGED
|
@@ -20,7 +20,10 @@ function getDefaults() {
|
|
|
20
20
|
lookupFromPathIndex: 0,
|
|
21
21
|
caches: false,
|
|
22
22
|
cookieSameSite: 'strict',
|
|
23
|
-
ignoreCase: true
|
|
23
|
+
ignoreCase: true,
|
|
24
|
+
convertDetectedLanguage: function convertDetectedLanguage(l) {
|
|
25
|
+
return l;
|
|
26
|
+
}
|
|
24
27
|
});
|
|
25
28
|
}
|
|
26
29
|
var LanguageDetector = function () {
|
|
@@ -40,6 +43,11 @@ var LanguageDetector = function () {
|
|
|
40
43
|
this.services = services;
|
|
41
44
|
this.options = utils.defaults(options, this.options || {}, getDefaults());
|
|
42
45
|
this.allOptions = allOptions;
|
|
46
|
+
if (typeof this.options.convertDetectedLanguage === 'string' && this.options.convertDetectedLanguage.indexOf('15897') > -1) {
|
|
47
|
+
this.options.convertDetectedLanguage = function (l) {
|
|
48
|
+
return l.replace('-', '_');
|
|
49
|
+
};
|
|
50
|
+
}
|
|
43
51
|
this.addDetector(cookieLookup);
|
|
44
52
|
this.addDetector(querystringLookup);
|
|
45
53
|
this.addDetector(pathLookup);
|
|
@@ -66,6 +74,9 @@ var LanguageDetector = function () {
|
|
|
66
74
|
detections = detections.filter(function (d) {
|
|
67
75
|
return d !== undefined && d !== null;
|
|
68
76
|
});
|
|
77
|
+
detections = detections.map(function (d) {
|
|
78
|
+
return _this.options.convertDetectedLanguage(d);
|
|
79
|
+
});
|
|
69
80
|
if (_this.services.languageUtils.getBestMatchFromCodes) {
|
|
70
81
|
found = _this.services.languageUtils.getBestMatchFromCodes(detections);
|
|
71
82
|
if (found) {
|
package/esm/index.d.mts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './index.js';
|
package/esm/index.d.ts
CHANGED
|
@@ -115,6 +115,11 @@ interface LanguageDetectorOptions {
|
|
|
115
115
|
caches?: LanguageDetectorCaches;
|
|
116
116
|
cookieExpirationDate?: Date;
|
|
117
117
|
cookieDomain?: string;
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* optional conversion function to use to modify the detected language code
|
|
121
|
+
*/
|
|
122
|
+
convertDetectedLanguage?: 'Iso15897' | ((lng: string) => string);
|
|
118
123
|
}
|
|
119
124
|
interface LanguageDetectorAllOptions {
|
|
120
125
|
fallbackLng: boolean | string | string[];
|
package/index.d.mts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './index.js';
|
package/index.d.ts
CHANGED
|
@@ -115,6 +115,11 @@ interface LanguageDetectorOptions {
|
|
|
115
115
|
caches?: LanguageDetectorCaches;
|
|
116
116
|
cookieExpirationDate?: Date;
|
|
117
117
|
cookieDomain?: string;
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* optional conversion function to use to modify the detected language code
|
|
121
|
+
*/
|
|
122
|
+
convertDetectedLanguage?: 'Iso15897' | ((lng: string) => string);
|
|
118
123
|
}
|
|
119
124
|
interface LanguageDetectorAllOptions {
|
|
120
125
|
fallbackLng: boolean | string | string[];
|
package/lib/LanguageDetector.js
CHANGED
|
@@ -20,7 +20,9 @@ function getDefaults () {
|
|
|
20
20
|
// cookieDomain: 'myDomain'
|
|
21
21
|
// cookiePath: '/my/path'
|
|
22
22
|
cookieSameSite: 'strict',
|
|
23
|
-
ignoreCase: true
|
|
23
|
+
ignoreCase: true,
|
|
24
|
+
|
|
25
|
+
convertDetectedLanguage: (l) => l
|
|
24
26
|
})
|
|
25
27
|
}
|
|
26
28
|
|
|
@@ -37,6 +39,10 @@ class LanguageDetector {
|
|
|
37
39
|
this.options = utils.defaults(options, this.options || {}, getDefaults())
|
|
38
40
|
this.allOptions = allOptions
|
|
39
41
|
|
|
42
|
+
if (typeof this.options.convertDetectedLanguage === 'string' && this.options.convertDetectedLanguage.indexOf('15897') > -1) {
|
|
43
|
+
this.options.convertDetectedLanguage = (l) => l.replace('-', '_')
|
|
44
|
+
}
|
|
45
|
+
|
|
40
46
|
this.addDetector(cookieLookup)
|
|
41
47
|
this.addDetector(querystringLookup)
|
|
42
48
|
this.addDetector(pathLookup)
|
|
@@ -61,6 +67,7 @@ class LanguageDetector {
|
|
|
61
67
|
if (!Array.isArray(detections)) detections = [detections]
|
|
62
68
|
|
|
63
69
|
detections = detections.filter((d) => d !== undefined && d !== null)
|
|
70
|
+
detections = detections.map((d) => this.options.convertDetectedLanguage(d))
|
|
64
71
|
|
|
65
72
|
if (this.services.languageUtils.getBestMatchFromCodes) { // new i18next v19.5.0
|
|
66
73
|
found = this.services.languageUtils.getBestMatchFromCodes(detections)
|
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "i18next-http-middleware",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.6.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./cjs/index.js",
|
|
7
|
-
"types": "./index.d.
|
|
7
|
+
"types": "./index.d.mts",
|
|
8
8
|
"exports": {
|
|
9
9
|
"./package.json": "./package.json",
|
|
10
10
|
".": {
|
|
11
11
|
"types": {
|
|
12
12
|
"require": "./cjs/index.d.ts",
|
|
13
|
-
"import": "./esm/index.d.
|
|
13
|
+
"import": "./esm/index.d.mts"
|
|
14
14
|
},
|
|
15
15
|
"module": "./esm/index.js",
|
|
16
16
|
"import": "./esm/index.js",
|
|
@@ -22,31 +22,31 @@
|
|
|
22
22
|
"default": "./cjs/index.js"
|
|
23
23
|
},
|
|
24
24
|
"./esm": {
|
|
25
|
-
"types": "./esm/index.d.
|
|
25
|
+
"types": "./esm/index.d.mts",
|
|
26
26
|
"default": "./esm/index.js"
|
|
27
27
|
}
|
|
28
28
|
},
|
|
29
29
|
"module": "./esm/index.js",
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@babel/cli": "7.23.0",
|
|
32
|
-
"@babel/core": "7.23.
|
|
33
|
-
"@babel/preset-env": "7.
|
|
32
|
+
"@babel/core": "7.23.3",
|
|
33
|
+
"@babel/preset-env": "7.23.3",
|
|
34
34
|
"@hapi/hapi": "^21.3.2",
|
|
35
|
-
"@types/express-serve-static-core": "^4.17.
|
|
36
|
-
"@koa/router": "12.0.
|
|
35
|
+
"@types/express-serve-static-core": "^4.17.41",
|
|
36
|
+
"@koa/router": "12.0.1",
|
|
37
37
|
"koa": "2.14.2",
|
|
38
38
|
"babel-plugin-add-module-exports": "1.0.4",
|
|
39
|
-
"eslint": "8.
|
|
39
|
+
"eslint": "8.53.0",
|
|
40
40
|
"eslint-config-standard": "17.1.0",
|
|
41
|
-
"eslint-plugin-import": "2.
|
|
42
|
-
"eslint-plugin-n": "16.1
|
|
41
|
+
"eslint-plugin-import": "2.29.0",
|
|
42
|
+
"eslint-plugin-n": "16.3.1",
|
|
43
43
|
"eslint-plugin-promise": "6.1.1",
|
|
44
44
|
"eslint-plugin-require-path-exists": "1.1.9",
|
|
45
45
|
"eslint-plugin-standard": "5.0.0",
|
|
46
46
|
"expect.js": "0.3.1",
|
|
47
|
-
"express": "4.
|
|
48
|
-
"fastify": "4.
|
|
49
|
-
"i18next": "23.
|
|
47
|
+
"express": "4.19.2",
|
|
48
|
+
"fastify": "4.24.3",
|
|
49
|
+
"i18next": "23.7.1",
|
|
50
50
|
"mocha": "10.2.0",
|
|
51
51
|
"supertest": "6.3.3",
|
|
52
52
|
"tsd": "0.29.0",
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
"license": "MIT",
|
|
71
71
|
"scripts": {
|
|
72
72
|
"lint": "eslint .",
|
|
73
|
-
"compile:esm": "rm -rf esm && mkdir esm && BABEL_ENV=esm babel lib -d esm && cp index.d.ts esm/index.d.ts",
|
|
73
|
+
"compile:esm": "rm -rf esm && mkdir esm && BABEL_ENV=esm babel lib -d esm && cp index.d.ts esm/index.d.ts && cp index.d.mts esm/index.d.mts",
|
|
74
74
|
"compile:cjs": "rm -rf cjs && mkdir cjs && BABEL_ENV=cjs babel lib -d cjs && cp index.d.ts cjs/index.d.ts && echo '{\"type\":\"commonjs\"}' > cjs/package.json",
|
|
75
75
|
"compile": "npm run compile:esm && npm run compile:cjs",
|
|
76
76
|
"build": "npm run compile",
|