i18next-http-middleware 3.5.0 → 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 +12 -1
- package/cjs/index.d.ts +5 -0
- package/esm/LanguageDetector.js +12 -1
- package/esm/index.d.ts +5 -0
- package/index.d.ts +5 -0
- package/lib/LanguageDetector.js +8 -1
- package/package.json +2 -2
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
|
@@ -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/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.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.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,6 +1,6 @@
|
|
|
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",
|
|
@@ -44,7 +44,7 @@
|
|
|
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.
|
|
47
|
+
"express": "4.19.2",
|
|
48
48
|
"fastify": "4.24.3",
|
|
49
49
|
"i18next": "23.7.1",
|
|
50
50
|
"mocha": "10.2.0",
|