@lingui/detect-locale 5.9.2 → 6.0.0-next.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/dist/index.d.mts +2 -1
- package/dist/index.mjs +4 -8
- package/package.json +13 -20
- package/dist/index.cjs +0 -122
- package/dist/index.d.cts +0 -25
- package/dist/index.d.ts +0 -25
package/dist/index.d.mts
CHANGED
|
@@ -22,4 +22,5 @@ type DetectParamsFunctions = string;
|
|
|
22
22
|
declare function detect(...args: any[]): LocaleString | null;
|
|
23
23
|
declare function multipleDetect(...args: any[]): LocaleString[];
|
|
24
24
|
|
|
25
|
-
export {
|
|
25
|
+
export { detect, detectFromCookie as fromCookie, detectHtmlTag as fromHtmlTag, detectFromNavigator as fromNavigator, detectFromPath as fromPath, detectFromStorage as fromStorage, detectFromSubdomain as fromSubdomain, detectFromUrl as fromUrl, multipleDetect };
|
|
26
|
+
export type { DetectParamsFunctions, LocaleString };
|
package/dist/index.mjs
CHANGED
|
@@ -70,8 +70,7 @@ function parse(query) {
|
|
|
70
70
|
while (part = parser.exec(query)) {
|
|
71
71
|
const key = decode(part[1]);
|
|
72
72
|
const value = decode(part[2]);
|
|
73
|
-
if (key === null || value === null || key in result)
|
|
74
|
-
continue;
|
|
73
|
+
if (key === null || value === null || key in result) continue;
|
|
75
74
|
result[key] = value;
|
|
76
75
|
}
|
|
77
76
|
return result;
|
|
@@ -85,8 +84,7 @@ function decode(input) {
|
|
|
85
84
|
}
|
|
86
85
|
|
|
87
86
|
function detectFromUrl(parameter, location = globalThis.location) {
|
|
88
|
-
if (!parameter)
|
|
89
|
-
throw new Error("fromUrl parameter is required");
|
|
87
|
+
if (!parameter) throw new Error("fromUrl parameter is required");
|
|
90
88
|
const result = parse(location.search)[parameter] || null;
|
|
91
89
|
return result;
|
|
92
90
|
}
|
|
@@ -94,8 +92,7 @@ function detectFromUrl(parameter, location = globalThis.location) {
|
|
|
94
92
|
function detect(...args) {
|
|
95
93
|
for (let i = 0; i < args.length; i++) {
|
|
96
94
|
const res = typeof args[i] === "function" ? args[i]() : args[i];
|
|
97
|
-
if (res)
|
|
98
|
-
return res;
|
|
95
|
+
if (res) return res;
|
|
99
96
|
}
|
|
100
97
|
return null;
|
|
101
98
|
}
|
|
@@ -103,8 +100,7 @@ function multipleDetect(...args) {
|
|
|
103
100
|
const locales = [];
|
|
104
101
|
for (let i = 0; i < args.length; i++) {
|
|
105
102
|
const res = typeof args[i] === "function" ? args[i]() : args[i];
|
|
106
|
-
if (res)
|
|
107
|
-
locales.push(res);
|
|
103
|
+
if (res) locales.push(res);
|
|
108
104
|
}
|
|
109
105
|
return locales;
|
|
110
106
|
}
|
package/package.json
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lingui/detect-locale",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.0-next.0",
|
|
4
|
+
"type": "module",
|
|
4
5
|
"sideEffects": false,
|
|
5
6
|
"description": "@Lingui package to help you find the correct browser/server locale",
|
|
6
|
-
"main": "./dist/index.cjs",
|
|
7
|
-
"module": "./dist/index.mjs",
|
|
8
|
-
"types": "./dist/index.d.ts",
|
|
9
7
|
"license": "MIT",
|
|
10
8
|
"keywords": [
|
|
11
9
|
"i18n",
|
|
@@ -17,8 +15,8 @@
|
|
|
17
15
|
"multilingual"
|
|
18
16
|
],
|
|
19
17
|
"scripts": {
|
|
20
|
-
"build": "
|
|
21
|
-
"
|
|
18
|
+
"build": "unbuild",
|
|
19
|
+
"check-types": "tsc --noEmit"
|
|
22
20
|
},
|
|
23
21
|
"author": {
|
|
24
22
|
"name": "Sergio Moreno",
|
|
@@ -34,19 +32,10 @@
|
|
|
34
32
|
"url": "https://github.com/lingui/js-lingui/issues"
|
|
35
33
|
},
|
|
36
34
|
"engines": {
|
|
37
|
-
"node": ">=
|
|
35
|
+
"node": ">=22.19.0"
|
|
38
36
|
},
|
|
39
37
|
"exports": {
|
|
40
|
-
".":
|
|
41
|
-
"require": {
|
|
42
|
-
"types": "./dist/index.d.cts",
|
|
43
|
-
"default": "./dist/index.cjs"
|
|
44
|
-
},
|
|
45
|
-
"import": {
|
|
46
|
-
"types": "./dist/index.d.mts",
|
|
47
|
-
"default": "./dist/index.mjs"
|
|
48
|
-
}
|
|
49
|
-
},
|
|
38
|
+
".": "./dist/index.mjs",
|
|
50
39
|
"./package.json": "./package.json"
|
|
51
40
|
},
|
|
52
41
|
"files": [
|
|
@@ -55,8 +44,12 @@
|
|
|
55
44
|
"dist/"
|
|
56
45
|
],
|
|
57
46
|
"devDependencies": {
|
|
58
|
-
"
|
|
59
|
-
"unbuild": "
|
|
47
|
+
"happy-dom": "^20.0.10",
|
|
48
|
+
"unbuild": "3.6.1",
|
|
49
|
+
"vitest": "4.0.18"
|
|
60
50
|
},
|
|
61
|
-
"
|
|
51
|
+
"unbuild": {
|
|
52
|
+
"declaration": "node16"
|
|
53
|
+
},
|
|
54
|
+
"gitHead": "a9576050487a4f7dfbc88db20814d5a1bb861c8c"
|
|
62
55
|
}
|
package/dist/index.cjs
DELETED
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
function getCookie(key) {
|
|
4
|
-
if (!key) {
|
|
5
|
-
return;
|
|
6
|
-
}
|
|
7
|
-
const cookies = globalThis.document.cookie ? globalThis.document.cookie.split("; ") : [];
|
|
8
|
-
const jar = {};
|
|
9
|
-
for (let i = 0; i < cookies.length; i++) {
|
|
10
|
-
const parts = cookies[i].split("=");
|
|
11
|
-
let value = parts.slice(1).join("=");
|
|
12
|
-
if (value[0] === '"') {
|
|
13
|
-
value = value.slice(1, -1);
|
|
14
|
-
}
|
|
15
|
-
try {
|
|
16
|
-
const foundKey = parts[0].replace(/(%[\dA-F]{2})+/gi, decodeURIComponent);
|
|
17
|
-
jar[foundKey] = value.replace(/(%[\dA-F]{2})+/gi, decodeURIComponent);
|
|
18
|
-
if (key === foundKey) {
|
|
19
|
-
break;
|
|
20
|
-
}
|
|
21
|
-
} catch (e) {
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
return key ? jar[key] : jar;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function detectFromCookie(key) {
|
|
28
|
-
return getCookie(key);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function detectFromPath(localePathIndex, location = globalThis.location) {
|
|
32
|
-
const locale = location.pathname.match(/\/([a-zA-Z-]*)/g);
|
|
33
|
-
if (Array.isArray(locale)) {
|
|
34
|
-
return locale[localePathIndex].replace("/", "");
|
|
35
|
-
}
|
|
36
|
-
return null;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function detectFromStorage(key, options = { useSessionStorage: false }) {
|
|
40
|
-
if (options.useSessionStorage) {
|
|
41
|
-
return globalThis.sessionStorage.getItem(key);
|
|
42
|
-
}
|
|
43
|
-
return globalThis.localStorage.getItem(key);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
function detectFromNavigator(navigator = globalThis.navigator) {
|
|
47
|
-
const result = navigator.language || navigator.userLanguage;
|
|
48
|
-
return result;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function detectFromSubdomain(localeSubdomainIndex, location = globalThis.location) {
|
|
52
|
-
const locale = location.href.match(
|
|
53
|
-
/(?:http[s]*:\/\/)*(.*?)\.(?=[^/]*\..{2,5})/gi
|
|
54
|
-
);
|
|
55
|
-
if (Array.isArray(locale)) {
|
|
56
|
-
return locale[localeSubdomainIndex].replace("http://", "").replace("https://", "").replace(".", "");
|
|
57
|
-
}
|
|
58
|
-
return null;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
function detectHtmlTag(htmlTagIdentifier, document = globalThis.document) {
|
|
62
|
-
if (htmlTagIdentifier) {
|
|
63
|
-
return document.documentElement.getAttribute(htmlTagIdentifier);
|
|
64
|
-
}
|
|
65
|
-
return null;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
function parse(query) {
|
|
69
|
-
const parser = /([^=?#&]+)=?([^&]*)/g;
|
|
70
|
-
const result = {};
|
|
71
|
-
let part;
|
|
72
|
-
while (part = parser.exec(query)) {
|
|
73
|
-
const key = decode(part[1]);
|
|
74
|
-
const value = decode(part[2]);
|
|
75
|
-
if (key === null || value === null || key in result)
|
|
76
|
-
continue;
|
|
77
|
-
result[key] = value;
|
|
78
|
-
}
|
|
79
|
-
return result;
|
|
80
|
-
}
|
|
81
|
-
function decode(input) {
|
|
82
|
-
try {
|
|
83
|
-
return decodeURIComponent(input.replace(/\+/g, " "));
|
|
84
|
-
} catch (e) {
|
|
85
|
-
return null;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
function detectFromUrl(parameter, location = globalThis.location) {
|
|
90
|
-
if (!parameter)
|
|
91
|
-
throw new Error("fromUrl parameter is required");
|
|
92
|
-
const result = parse(location.search)[parameter] || null;
|
|
93
|
-
return result;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
function detect(...args) {
|
|
97
|
-
for (let i = 0; i < args.length; i++) {
|
|
98
|
-
const res = typeof args[i] === "function" ? args[i]() : args[i];
|
|
99
|
-
if (res)
|
|
100
|
-
return res;
|
|
101
|
-
}
|
|
102
|
-
return null;
|
|
103
|
-
}
|
|
104
|
-
function multipleDetect(...args) {
|
|
105
|
-
const locales = [];
|
|
106
|
-
for (let i = 0; i < args.length; i++) {
|
|
107
|
-
const res = typeof args[i] === "function" ? args[i]() : args[i];
|
|
108
|
-
if (res)
|
|
109
|
-
locales.push(res);
|
|
110
|
-
}
|
|
111
|
-
return locales;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
exports.detect = detect;
|
|
115
|
-
exports.fromCookie = detectFromCookie;
|
|
116
|
-
exports.fromHtmlTag = detectHtmlTag;
|
|
117
|
-
exports.fromNavigator = detectFromNavigator;
|
|
118
|
-
exports.fromPath = detectFromPath;
|
|
119
|
-
exports.fromStorage = detectFromStorage;
|
|
120
|
-
exports.fromSubdomain = detectFromSubdomain;
|
|
121
|
-
exports.fromUrl = detectFromUrl;
|
|
122
|
-
exports.multipleDetect = multipleDetect;
|
package/dist/index.d.cts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
declare function detectFromCookie(key: string): LocaleString;
|
|
2
|
-
|
|
3
|
-
declare function detectFromPath(localePathIndex: number, location?: Partial<Location>): LocaleString;
|
|
4
|
-
|
|
5
|
-
declare function detectFromStorage(key: string, options?: {
|
|
6
|
-
useSessionStorage: boolean;
|
|
7
|
-
}): LocaleString;
|
|
8
|
-
|
|
9
|
-
type IE11NavigatorLanguage = {
|
|
10
|
-
userLanguage?: string;
|
|
11
|
-
};
|
|
12
|
-
declare function detectFromNavigator(navigator?: Partial<Navigator & IE11NavigatorLanguage>): LocaleString;
|
|
13
|
-
|
|
14
|
-
declare function detectFromSubdomain(localeSubdomainIndex: number, location?: Partial<Location>): LocaleString;
|
|
15
|
-
|
|
16
|
-
declare function detectHtmlTag(htmlTagIdentifier: string, document?: Partial<Document>): LocaleString;
|
|
17
|
-
|
|
18
|
-
declare function detectFromUrl(parameter: string, location?: Partial<Location>): LocaleString;
|
|
19
|
-
|
|
20
|
-
type LocaleString = string;
|
|
21
|
-
type DetectParamsFunctions = string;
|
|
22
|
-
declare function detect(...args: any[]): LocaleString | null;
|
|
23
|
-
declare function multipleDetect(...args: any[]): LocaleString[];
|
|
24
|
-
|
|
25
|
-
export { type DetectParamsFunctions, type LocaleString, detect, detectFromCookie as fromCookie, detectHtmlTag as fromHtmlTag, detectFromNavigator as fromNavigator, detectFromPath as fromPath, detectFromStorage as fromStorage, detectFromSubdomain as fromSubdomain, detectFromUrl as fromUrl, multipleDetect };
|
package/dist/index.d.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
declare function detectFromCookie(key: string): LocaleString;
|
|
2
|
-
|
|
3
|
-
declare function detectFromPath(localePathIndex: number, location?: Partial<Location>): LocaleString;
|
|
4
|
-
|
|
5
|
-
declare function detectFromStorage(key: string, options?: {
|
|
6
|
-
useSessionStorage: boolean;
|
|
7
|
-
}): LocaleString;
|
|
8
|
-
|
|
9
|
-
type IE11NavigatorLanguage = {
|
|
10
|
-
userLanguage?: string;
|
|
11
|
-
};
|
|
12
|
-
declare function detectFromNavigator(navigator?: Partial<Navigator & IE11NavigatorLanguage>): LocaleString;
|
|
13
|
-
|
|
14
|
-
declare function detectFromSubdomain(localeSubdomainIndex: number, location?: Partial<Location>): LocaleString;
|
|
15
|
-
|
|
16
|
-
declare function detectHtmlTag(htmlTagIdentifier: string, document?: Partial<Document>): LocaleString;
|
|
17
|
-
|
|
18
|
-
declare function detectFromUrl(parameter: string, location?: Partial<Location>): LocaleString;
|
|
19
|
-
|
|
20
|
-
type LocaleString = string;
|
|
21
|
-
type DetectParamsFunctions = string;
|
|
22
|
-
declare function detect(...args: any[]): LocaleString | null;
|
|
23
|
-
declare function multipleDetect(...args: any[]): LocaleString[];
|
|
24
|
-
|
|
25
|
-
export { type DetectParamsFunctions, type LocaleString, detect, detectFromCookie as fromCookie, detectHtmlTag as fromHtmlTag, detectFromNavigator as fromNavigator, detectFromPath as fromPath, detectFromStorage as fromStorage, detectFromSubdomain as fromSubdomain, detectFromUrl as fromUrl, multipleDetect };
|