@arcblock/ux 2.9.57 → 2.9.59
Sign up to get free protection for your applications and to get access to all the features.
- package/es/SessionBlocklet/index.js +2 -1
- package/es/Util/index.js +30 -0
- package/lib/SessionBlocklet/index.js +3 -2
- package/lib/Util/index.js +33 -2
- package/package.json +5 -5
- package/src/SessionBlocklet/index.jsx +2 -1
- package/src/Util/index.js +28 -0
@@ -9,6 +9,7 @@ import Button from '../Button';
|
|
9
9
|
import { temp as colors } from '../Colors';
|
10
10
|
import { AUTH_SERVICE_PREFIX, NAVIGATION_URL } from '../Util/constant';
|
11
11
|
import SessionPermission from '../SessionPermission';
|
12
|
+
import { getTranslation } from '../Util';
|
12
13
|
import { jsx as _jsx } from "react/jsx-runtime";
|
13
14
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
14
15
|
import { Fragment as _Fragment } from "react/jsx-runtime";
|
@@ -132,7 +133,7 @@ export default function SessionBlocklet({
|
|
132
133
|
textAlign: 'center',
|
133
134
|
lineHeight: 'normal'
|
134
135
|
},
|
135
|
-
children: item.title
|
136
|
+
children: getTranslation(item.title, locale)
|
136
137
|
})]
|
137
138
|
})
|
138
139
|
}, item.id))
|
package/es/Util/index.js
CHANGED
@@ -329,4 +329,34 @@ export const getDIDColor = did => {
|
|
329
329
|
} catch {
|
330
330
|
return null;
|
331
331
|
}
|
332
|
+
};
|
333
|
+
|
334
|
+
/**
|
335
|
+
* Retrieves the appropriate translation based on the locale, with fallback options.
|
336
|
+
*
|
337
|
+
* @param {Object|string} translations - The translations object or string to retrieve translation from.
|
338
|
+
* @param {string} locale - The locale to use for retrieving the translation.
|
339
|
+
* @param {Object} options - Additional options for fallbackLocale and defaultValue.
|
340
|
+
* @param {string} [options.fallbackLocale='en'] - The fallback locale to use if the translation for the specified locale is not found.
|
341
|
+
* @param {string} [options.defaultValue='unknown'] - The default value to return if no translation is found.
|
342
|
+
* @return {string} The translated string based on the locale, with fallback options if necessary.
|
343
|
+
*/
|
344
|
+
export const getTranslation = (translations, locale, {
|
345
|
+
fallbackLocale = 'en',
|
346
|
+
defaultValue = 'unknown'
|
347
|
+
} = {}) => {
|
348
|
+
if (typeof translations === 'string') {
|
349
|
+
return translations;
|
350
|
+
}
|
351
|
+
let translation;
|
352
|
+
if (locale) {
|
353
|
+
translation = translations[locale];
|
354
|
+
}
|
355
|
+
if (!translation || typeof translation !== 'string') {
|
356
|
+
translation = translations[fallbackLocale];
|
357
|
+
}
|
358
|
+
if (!translation || typeof translation !== 'string') {
|
359
|
+
translation = defaultValue;
|
360
|
+
}
|
361
|
+
return translation;
|
332
362
|
};
|
@@ -15,6 +15,7 @@ var _Button = _interopRequireDefault(require("../Button"));
|
|
15
15
|
var _Colors = require("../Colors");
|
16
16
|
var _constant = require("../Util/constant");
|
17
17
|
var _SessionPermission = _interopRequireDefault(require("../SessionPermission"));
|
18
|
+
var _Util = require("../Util");
|
18
19
|
var _jsxRuntime = require("react/jsx-runtime");
|
19
20
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
20
21
|
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; }
|
@@ -110,7 +111,7 @@ function SessionBlocklet(_ref) {
|
|
110
111
|
p: 0
|
111
112
|
},
|
112
113
|
children: sessionMenuList.map(item => {
|
113
|
-
var _item$component
|
114
|
+
var _item$component;
|
114
115
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.ListItem, {
|
115
116
|
disablePadding: true,
|
116
117
|
children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.ListItemButton, {
|
@@ -148,7 +149,7 @@ function SessionBlocklet(_ref) {
|
|
148
149
|
textAlign: 'center',
|
149
150
|
lineHeight: 'normal'
|
150
151
|
},
|
151
|
-
children: ((
|
152
|
+
children: (0, _Util.getTranslation)(item.title, locale)
|
152
153
|
})]
|
153
154
|
})
|
154
155
|
}, item.id);
|
package/lib/Util/index.js
CHANGED
@@ -12,7 +12,7 @@ exports.getCookieOptions = getCookieOptions;
|
|
12
12
|
exports.getCopyright = getCopyright;
|
13
13
|
exports.getDIDColor = void 0;
|
14
14
|
exports.getDateTool = getDateTool;
|
15
|
-
exports.isUrl = exports.isEthereumDid = exports.getVisitorId = exports.getUserAvatar = exports.getTimezone = exports.getFontSize = void 0;
|
15
|
+
exports.isUrl = exports.isEthereumDid = exports.getVisitorId = exports.getUserAvatar = exports.getTranslation = exports.getTimezone = exports.getFontSize = void 0;
|
16
16
|
exports.mergeProps = mergeProps;
|
17
17
|
exports.openWebWallet = openWebWallet;
|
18
18
|
exports.parseQuery = parseQuery;
|
@@ -378,4 +378,35 @@ const getDIDColor = did => {
|
|
378
378
|
return null;
|
379
379
|
}
|
380
380
|
};
|
381
|
-
|
381
|
+
|
382
|
+
/**
|
383
|
+
* Retrieves the appropriate translation based on the locale, with fallback options.
|
384
|
+
*
|
385
|
+
* @param {Object|string} translations - The translations object or string to retrieve translation from.
|
386
|
+
* @param {string} locale - The locale to use for retrieving the translation.
|
387
|
+
* @param {Object} options - Additional options for fallbackLocale and defaultValue.
|
388
|
+
* @param {string} [options.fallbackLocale='en'] - The fallback locale to use if the translation for the specified locale is not found.
|
389
|
+
* @param {string} [options.defaultValue='unknown'] - The default value to return if no translation is found.
|
390
|
+
* @return {string} The translated string based on the locale, with fallback options if necessary.
|
391
|
+
*/
|
392
|
+
exports.getDIDColor = getDIDColor;
|
393
|
+
const getTranslation = exports.getTranslation = function getTranslation(translations, locale) {
|
394
|
+
let {
|
395
|
+
fallbackLocale = 'en',
|
396
|
+
defaultValue = 'unknown'
|
397
|
+
} = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
398
|
+
if (typeof translations === 'string') {
|
399
|
+
return translations;
|
400
|
+
}
|
401
|
+
let translation;
|
402
|
+
if (locale) {
|
403
|
+
translation = translations[locale];
|
404
|
+
}
|
405
|
+
if (!translation || typeof translation !== 'string') {
|
406
|
+
translation = translations[fallbackLocale];
|
407
|
+
}
|
408
|
+
if (!translation || typeof translation !== 'string') {
|
409
|
+
translation = defaultValue;
|
410
|
+
}
|
411
|
+
return translation;
|
412
|
+
};
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@arcblock/ux",
|
3
|
-
"version": "2.9.
|
3
|
+
"version": "2.9.59",
|
4
4
|
"description": "Common used react components for arcblock products",
|
5
5
|
"keywords": [
|
6
6
|
"react",
|
@@ -358,12 +358,12 @@
|
|
358
358
|
"@mui/material": "^5.15.0",
|
359
359
|
"react": ">=18.2.0"
|
360
360
|
},
|
361
|
-
"gitHead": "
|
361
|
+
"gitHead": "686579a3c6f29287149a7cb9bb15ba826bda153a",
|
362
362
|
"dependencies": {
|
363
363
|
"@arcblock/did-motif": "^1.1.13",
|
364
|
-
"@arcblock/icons": "^2.9.
|
365
|
-
"@arcblock/nft-display": "^2.9.
|
366
|
-
"@arcblock/react-hooks": "^2.9.
|
364
|
+
"@arcblock/icons": "^2.9.59",
|
365
|
+
"@arcblock/nft-display": "^2.9.59",
|
366
|
+
"@arcblock/react-hooks": "^2.9.59",
|
367
367
|
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
|
368
368
|
"@emotion/react": "^11.10.4",
|
369
369
|
"@emotion/styled": "^11.10.4",
|
@@ -21,6 +21,7 @@ import Button from '../Button';
|
|
21
21
|
import { temp as colors } from '../Colors';
|
22
22
|
import { AUTH_SERVICE_PREFIX, NAVIGATION_URL } from '../Util/constant';
|
23
23
|
import SessionPermission from '../SessionPermission';
|
24
|
+
import { getTranslation } from '../Util';
|
24
25
|
|
25
26
|
export default function SessionBlocklet({ session, locale, size }) {
|
26
27
|
const blocklet = window?.blocklet || {};
|
@@ -136,7 +137,7 @@ export default function SessionBlocklet({ session, locale, size }) {
|
|
136
137
|
textAlign: 'center',
|
137
138
|
lineHeight: 'normal',
|
138
139
|
}}>
|
139
|
-
{item.title
|
140
|
+
{getTranslation(item.title, locale)}
|
140
141
|
</Typography>
|
141
142
|
</ListItemButton>
|
142
143
|
</ListItem>
|
package/src/Util/index.js
CHANGED
@@ -372,3 +372,31 @@ export const getDIDColor = (did) => {
|
|
372
372
|
return null;
|
373
373
|
}
|
374
374
|
};
|
375
|
+
|
376
|
+
/**
|
377
|
+
* Retrieves the appropriate translation based on the locale, with fallback options.
|
378
|
+
*
|
379
|
+
* @param {Object|string} translations - The translations object or string to retrieve translation from.
|
380
|
+
* @param {string} locale - The locale to use for retrieving the translation.
|
381
|
+
* @param {Object} options - Additional options for fallbackLocale and defaultValue.
|
382
|
+
* @param {string} [options.fallbackLocale='en'] - The fallback locale to use if the translation for the specified locale is not found.
|
383
|
+
* @param {string} [options.defaultValue='unknown'] - The default value to return if no translation is found.
|
384
|
+
* @return {string} The translated string based on the locale, with fallback options if necessary.
|
385
|
+
*/
|
386
|
+
export const getTranslation = (translations, locale, { fallbackLocale = 'en', defaultValue = 'unknown' } = {}) => {
|
387
|
+
if (typeof translations === 'string') {
|
388
|
+
return translations;
|
389
|
+
}
|
390
|
+
let translation;
|
391
|
+
if (locale) {
|
392
|
+
translation = translations[locale];
|
393
|
+
}
|
394
|
+
if (!translation || typeof translation !== 'string') {
|
395
|
+
translation = translations[fallbackLocale];
|
396
|
+
}
|
397
|
+
if (!translation || typeof translation !== 'string') {
|
398
|
+
translation = defaultValue;
|
399
|
+
}
|
400
|
+
|
401
|
+
return translation;
|
402
|
+
};
|