@arcblock/ux 2.4.12 → 2.4.13
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/lib/Locale/context.js +16 -1
- package/package.json +4 -4
- package/src/Locale/context.js +13 -1
package/lib/Locale/context.js
CHANGED
@@ -56,11 +56,26 @@ const getLocaleFromSearchParams = function getLocaleFromSearchParams() {
|
|
56
56
|
return null;
|
57
57
|
};
|
58
58
|
|
59
|
+
const setLocaleParam = function setLocaleParam(locale) {
|
60
|
+
let url = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : window.location.href;
|
61
|
+
const urlObj = new URL(url);
|
62
|
+
const hasLocaleParam = urlObj.searchParams.has('locale');
|
63
|
+
|
64
|
+
if (hasLocaleParam) {
|
65
|
+
urlObj.searchParams.set('locale', locale);
|
66
|
+
window.history.replaceState({}, '', urlObj.href);
|
67
|
+
}
|
68
|
+
};
|
69
|
+
|
59
70
|
const getLocale = locale => locale || getLocaleFromSearchParams() || _jsCookie.default.get(cookieName) || (0, _browserLang.default)(langParams);
|
60
71
|
|
61
72
|
exports.getLocale = getLocale;
|
62
73
|
|
63
|
-
const setLocale = locale =>
|
74
|
+
const setLocale = locale => {
|
75
|
+
_jsCookie.default.set(cookieName, locale, (0, _Util.getCookieOptions)());
|
76
|
+
|
77
|
+
setLocaleParam(locale);
|
78
|
+
};
|
64
79
|
|
65
80
|
exports.setLocale = setLocale;
|
66
81
|
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@arcblock/ux",
|
3
|
-
"version": "2.4.
|
3
|
+
"version": "2.4.13",
|
4
4
|
"description": "Common used react components for arcblock products",
|
5
5
|
"keywords": [
|
6
6
|
"react",
|
@@ -47,10 +47,10 @@
|
|
47
47
|
"react": ">=18.1.0",
|
48
48
|
"react-ga": "^2.7.0"
|
49
49
|
},
|
50
|
-
"gitHead": "
|
50
|
+
"gitHead": "f374463572e397b959e9c1ce70cdbc9f53f99076",
|
51
51
|
"dependencies": {
|
52
|
-
"@arcblock/icons": "^2.4.
|
53
|
-
"@arcblock/react-hooks": "^2.4.
|
52
|
+
"@arcblock/icons": "^2.4.13",
|
53
|
+
"@arcblock/react-hooks": "^2.4.13",
|
54
54
|
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
|
55
55
|
"@emotion/react": "^11.10.0",
|
56
56
|
"@emotion/styled": "^11.10.0",
|
package/src/Locale/context.js
CHANGED
@@ -25,9 +25,21 @@ const getLocaleFromSearchParams = (url = window.location.href) => {
|
|
25
25
|
return null;
|
26
26
|
};
|
27
27
|
|
28
|
+
const setLocaleParam = (locale, url = window.location.href) => {
|
29
|
+
const urlObj = new URL(url);
|
30
|
+
const hasLocaleParam = urlObj.searchParams.has('locale');
|
31
|
+
if (hasLocaleParam) {
|
32
|
+
urlObj.searchParams.set('locale', locale);
|
33
|
+
window.history.replaceState({}, '', urlObj.href);
|
34
|
+
}
|
35
|
+
};
|
36
|
+
|
28
37
|
const getLocale = (locale) =>
|
29
38
|
locale || getLocaleFromSearchParams() || Cookie.get(cookieName) || browserLang(langParams);
|
30
|
-
const setLocale = (locale) =>
|
39
|
+
const setLocale = (locale) => {
|
40
|
+
Cookie.set(cookieName, locale, getCookieOptions());
|
41
|
+
setLocaleParam(locale);
|
42
|
+
};
|
31
43
|
|
32
44
|
const replace = (template, data) =>
|
33
45
|
template.replace(/{(\w*)}/g, (m, key) => (data.hasOwnProperty(key) ? data[key] : ''));
|