@alicloud/alfa-core 1.5.10 → 1.5.11

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.
@@ -5,6 +5,23 @@ import { getRelease } from './getRelease';
5
5
  import cache from './cacheManager';
6
6
  import { getMicroAppLocale } from './oss';
7
7
  import { getEnv } from './env';
8
+ var findLocaleEntry = function findLocaleEntry(localeVersionMap, locale) {
9
+ var matchKey = Object.keys(localeVersionMap || {}).find(function (key) {
10
+ return key && key.toLowerCase() === locale.toLowerCase();
11
+ });
12
+ var entry = matchKey && (localeVersionMap === null || localeVersionMap === void 0 ? void 0 : localeVersionMap[matchKey]);
13
+ if (matchKey && entry) return {
14
+ matchKey: matchKey,
15
+ entry: entry
16
+ };
17
+ return undefined;
18
+ };
19
+ var getFallbackLocale = function getFallbackLocale() {
20
+ var _window, _window$ALIYUN_CONSOL;
21
+ var channel = (_window = window) === null || _window === void 0 ? void 0 : (_window$ALIYUN_CONSOL = _window.ALIYUN_CONSOLE_CONFIG) === null || _window$ALIYUN_CONSOL === void 0 ? void 0 : _window$ALIYUN_CONSOL.CHANNEL;
22
+ return channel === 'SIN' ? 'en_US' : 'zh_CN';
23
+ };
24
+
8
25
  /**
9
26
  * 获取国际化文案
10
27
  * @param config
@@ -12,8 +29,8 @@ import { getEnv } from './env';
12
29
  */
13
30
  export var getI18nMessages = /*#__PURE__*/function () {
14
31
  var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(config) {
15
- var _releaseConfig$distT, _releaseConfig$locale, _releaseConfig$locale2, _releaseConfig$locale3;
16
- var releaseConfig, logger, locale, localeVersion, matchKey, localeEntry, messages, _t, _t2;
32
+ var _releaseConfig$distT, _releaseConfig$locale, _matched, _matched2;
33
+ var releaseConfig, logger, locale, localeVersion, localeVersionMap, matched, localeEntry, resolvedLocale, messages, _t, _t2;
17
34
  return _regeneratorRuntime.wrap(function (_context) {
18
35
  while (1) switch (_context.prev = _context.next) {
19
36
  case 0:
@@ -24,10 +41,13 @@ export var getI18nMessages = /*#__PURE__*/function () {
24
41
  logger = config.logger;
25
42
  locale = getLocale(config.locale);
26
43
  localeVersion = ((_releaseConfig$distT = releaseConfig['dist-tags']) === null || _releaseConfig$distT === void 0 ? void 0 : _releaseConfig$distT['locales-latest']) || '';
27
- matchKey = Object.keys(((_releaseConfig$locale = releaseConfig['locales-versions']) === null || _releaseConfig$locale === void 0 ? void 0 : _releaseConfig$locale[localeVersion]) || {}).find(function (key) {
28
- return key && key.toLowerCase() === locale.toLowerCase();
29
- });
30
- localeEntry = matchKey && ((_releaseConfig$locale2 = releaseConfig['locales-versions']) === null || _releaseConfig$locale2 === void 0 ? void 0 : (_releaseConfig$locale3 = _releaseConfig$locale2[localeVersion]) === null || _releaseConfig$locale3 === void 0 ? void 0 : _releaseConfig$locale3[matchKey]);
44
+ localeVersionMap = (_releaseConfig$locale = releaseConfig['locales-versions']) === null || _releaseConfig$locale === void 0 ? void 0 : _releaseConfig$locale[localeVersion];
45
+ matched = findLocaleEntry(localeVersionMap, locale);
46
+ if (!matched) {
47
+ matched = findLocaleEntry(localeVersionMap, getFallbackLocale());
48
+ }
49
+ localeEntry = (_matched = matched) === null || _matched === void 0 ? void 0 : _matched.entry;
50
+ resolvedLocale = ((_matched2 = matched) === null || _matched2 === void 0 ? void 0 : _matched2.matchKey) || locale;
31
51
  messages = {};
32
52
  if (localeVersion) {
33
53
  _context.next = 2;
@@ -53,7 +73,7 @@ export var getI18nMessages = /*#__PURE__*/function () {
53
73
  _t = _context["catch"](2);
54
74
  _context.prev = 6;
55
75
  _context.next = 7;
56
- return getMicroAppLocale(config.name, localeVersion, locale, getEnv(config.env));
76
+ return getMicroAppLocale(config.name, localeVersion, resolvedLocale, getEnv(config.env));
57
77
  case 7:
58
78
  messages = _context.sent;
59
79
  _context.next = 9;
@@ -12,6 +12,23 @@ var _getRelease = require("./getRelease");
12
12
  var _cacheManager = _interopRequireDefault(require("./cacheManager"));
13
13
  var _oss = require("./oss");
14
14
  var _env = require("./env");
15
+ var findLocaleEntry = function findLocaleEntry(localeVersionMap, locale) {
16
+ var matchKey = Object.keys(localeVersionMap || {}).find(function (key) {
17
+ return key && key.toLowerCase() === locale.toLowerCase();
18
+ });
19
+ var entry = matchKey && (localeVersionMap === null || localeVersionMap === void 0 ? void 0 : localeVersionMap[matchKey]);
20
+ if (matchKey && entry) return {
21
+ matchKey: matchKey,
22
+ entry: entry
23
+ };
24
+ return undefined;
25
+ };
26
+ var getFallbackLocale = function getFallbackLocale() {
27
+ var _window, _window$ALIYUN_CONSOL;
28
+ var channel = (_window = window) === null || _window === void 0 ? void 0 : (_window$ALIYUN_CONSOL = _window.ALIYUN_CONSOLE_CONFIG) === null || _window$ALIYUN_CONSOL === void 0 ? void 0 : _window$ALIYUN_CONSOL.CHANNEL;
29
+ return channel === 'SIN' ? 'en_US' : 'zh_CN';
30
+ };
31
+
15
32
  /**
16
33
  * 获取国际化文案
17
34
  * @param config
@@ -19,8 +36,8 @@ var _env = require("./env");
19
36
  */
20
37
  var getI18nMessages = exports.getI18nMessages = /*#__PURE__*/function () {
21
38
  var _ref = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee(config) {
22
- var _releaseConfig$distT, _releaseConfig$locale, _releaseConfig$locale2, _releaseConfig$locale3;
23
- var releaseConfig, logger, locale, localeVersion, matchKey, localeEntry, messages, _t, _t2;
39
+ var _releaseConfig$distT, _releaseConfig$locale, _matched, _matched2;
40
+ var releaseConfig, logger, locale, localeVersion, localeVersionMap, matched, localeEntry, resolvedLocale, messages, _t, _t2;
24
41
  return _regenerator.default.wrap(function (_context) {
25
42
  while (1) switch (_context.prev = _context.next) {
26
43
  case 0:
@@ -31,10 +48,13 @@ var getI18nMessages = exports.getI18nMessages = /*#__PURE__*/function () {
31
48
  logger = config.logger;
32
49
  locale = (0, _locale.getLocale)(config.locale);
33
50
  localeVersion = ((_releaseConfig$distT = releaseConfig['dist-tags']) === null || _releaseConfig$distT === void 0 ? void 0 : _releaseConfig$distT['locales-latest']) || '';
34
- matchKey = Object.keys(((_releaseConfig$locale = releaseConfig['locales-versions']) === null || _releaseConfig$locale === void 0 ? void 0 : _releaseConfig$locale[localeVersion]) || {}).find(function (key) {
35
- return key && key.toLowerCase() === locale.toLowerCase();
36
- });
37
- localeEntry = matchKey && ((_releaseConfig$locale2 = releaseConfig['locales-versions']) === null || _releaseConfig$locale2 === void 0 ? void 0 : (_releaseConfig$locale3 = _releaseConfig$locale2[localeVersion]) === null || _releaseConfig$locale3 === void 0 ? void 0 : _releaseConfig$locale3[matchKey]);
51
+ localeVersionMap = (_releaseConfig$locale = releaseConfig['locales-versions']) === null || _releaseConfig$locale === void 0 ? void 0 : _releaseConfig$locale[localeVersion];
52
+ matched = findLocaleEntry(localeVersionMap, locale);
53
+ if (!matched) {
54
+ matched = findLocaleEntry(localeVersionMap, getFallbackLocale());
55
+ }
56
+ localeEntry = (_matched = matched) === null || _matched === void 0 ? void 0 : _matched.entry;
57
+ resolvedLocale = ((_matched2 = matched) === null || _matched2 === void 0 ? void 0 : _matched2.matchKey) || locale;
38
58
  messages = {};
39
59
  if (localeVersion) {
40
60
  _context.next = 2;
@@ -60,7 +80,7 @@ var getI18nMessages = exports.getI18nMessages = /*#__PURE__*/function () {
60
80
  _t = _context["catch"](2);
61
81
  _context.prev = 6;
62
82
  _context.next = 7;
63
- return (0, _oss.getMicroAppLocale)(config.name, localeVersion, locale, (0, _env.getEnv)(config.env));
83
+ return (0, _oss.getMicroAppLocale)(config.name, localeVersion, resolvedLocale, (0, _env.getEnv)(config.env));
64
84
  case 7:
65
85
  messages = _context.sent;
66
86
  _context.next = 9;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alicloud/alfa-core",
3
- "version": "1.5.10",
3
+ "version": "1.5.11",
4
4
  "description": "MicroFront End SDK for alicloud",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",
@@ -16,6 +16,7 @@
16
16
  "@types/axios": "^0.14.0",
17
17
  "@types/chai": "^4.1.7",
18
18
  "@types/jest": "^23.3.13",
19
+ "@types/node": "^20.0.0",
19
20
  "@types/qs": "^6.9.18",
20
21
  "@types/react": "^16.9.2",
21
22
  "jest": "^23.6.0",
@@ -32,7 +33,7 @@
32
33
  "crypto-js": "^4.1.1",
33
34
  "qs": "^6.14.0",
34
35
  "tslib": "^2.4.0",
35
- "@alicloud/console-os-kernal": "^1.4.38"
36
+ "@alicloud/console-os-kernal": "^1.4.39"
36
37
  },
37
38
  "scripts": {
38
39
  "build": "npm run babel && npm run babel:esm && npm run types",