@vtx/modals2 6.0.0-beta.0 → 6.0.0-beta.1

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.
@@ -10,7 +10,6 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
10
10
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
11
11
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
12
12
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
13
- import { useIntl } from 'dumi';
14
13
  import zhCN from "../locales/zh-CN.json";
15
14
  import enUS from "../locales/en.json";
16
15
  var keyFieldMap = {
@@ -57,9 +56,9 @@ export function getTranslationKey(text) {
57
56
  return undefined;
58
57
  }
59
58
  var match = text.match(/^t\('([^']+)'\)$/);
60
- return match && match[1];
59
+ return match === null || match === void 0 ? void 0 : match[1];
61
60
  }
62
- function getHashLocale() {
61
+ function getHashLanguage() {
63
62
  if (typeof window === 'undefined') {
64
63
  return undefined;
65
64
  }
@@ -70,13 +69,13 @@ function getHashLocale() {
70
69
  }
71
70
  return new URLSearchParams(hash.slice(queryIndex + 1)).get('vtxLanguage') || undefined;
72
71
  }
73
- export function getRuntimeLocale() {
74
- var _window$localStorage, _window$localStorage2;
75
- var searchLocale = typeof window !== 'undefined' ? new URLSearchParams(window.location.search).get('vtxLanguage') : undefined;
76
- var hashLocale = getHashLocale();
77
- var storedLocale = typeof window !== 'undefined' ? ((_window$localStorage = window.localStorage) === null || _window$localStorage === void 0 ? void 0 : _window$localStorage.getItem('vtxLanguage')) || ((_window$localStorage2 = window.localStorage) === null || _window$localStorage2 === void 0 ? void 0 : _window$localStorage2.getItem('vtxLanguage')) : undefined;
78
- var locale = searchLocale || hashLocale || storedLocale;
79
- return locale === 'en-US' || locale === 'en_US' || locale === 'en-us' ? 'en-US' : 'zh-CN';
72
+ export function getRuntimeLanguage() {
73
+ var _window$localStorage;
74
+ var searchLanguage = typeof window !== 'undefined' ? new URLSearchParams(window.location.search).get('vtxLanguage') : undefined;
75
+ var hashLanguage = getHashLanguage();
76
+ var storedLanguage = typeof window !== 'undefined' ? (_window$localStorage = window.localStorage) === null || _window$localStorage === void 0 ? void 0 : _window$localStorage.getItem('vtxLanguage') : undefined;
77
+ var language = searchLanguage || hashLanguage || storedLanguage;
78
+ return language === 'en-US' || language === 'en_US' || language === 'en-us' || language === 'en' ? 'en-US' : 'zh-CN';
80
79
  }
81
80
  function formatMessage(template, values) {
82
81
  if (!values) {
@@ -98,20 +97,20 @@ export function translateLocaleText(text, values) {
98
97
  if (!key) {
99
98
  return text;
100
99
  }
101
- var locale = getRuntimeLocale();
102
- var localeData = locale === 'en-US' ? enUS : zhCN;
100
+ var language = getRuntimeLanguage();
101
+ var localeData = language === 'en-US' ? enUS : zhCN;
103
102
  return formatMessage(localeData[key] || zhCN[key] || key, values);
104
103
  }
105
104
  function applyKeyFields(source, t) {
106
105
  var next = _objectSpread({}, source);
107
- Object.entries(keyFieldMap).forEach(function (_ref) {
108
- var _ref2 = _slicedToArray(_ref, 2),
109
- keyField = _ref2[0],
110
- targetField = _ref2[1];
106
+ for (var _i = 0, _Object$entries = Object.entries(keyFieldMap); _i < _Object$entries.length; _i++) {
107
+ var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
108
+ keyField = _Object$entries$_i[0],
109
+ targetField = _Object$entries$_i[1];
111
110
  if (typeof source[keyField] === 'string' && source[keyField]) {
112
111
  next[targetField] = translationByKey(source[keyField], t);
113
112
  }
114
- });
113
+ }
115
114
  return next;
116
115
  }
117
116
  function _translationConst(lists, t) {
@@ -193,19 +192,18 @@ function _translationConst(lists, t) {
193
192
  return loopOptions(lists);
194
193
  }
195
194
  export { _translationConst as translationConst };
196
- export function getT(intl) {
195
+ export function getT() {
197
196
  var t = function t(id, values) {
198
- return intl.formatMessage({
199
- id: id
200
- }, values);
197
+ var language = getRuntimeLanguage();
198
+ var localeData = language === 'en-US' ? enUS : zhCN;
199
+ return formatMessage(localeData[id] || zhCN[id] || id, values);
201
200
  };
202
201
  return {
203
202
  t: t
204
203
  };
205
204
  }
206
205
  export function useTranslation() {
207
- var intl = useIntl();
208
- var _getT = getT(intl),
206
+ var _getT = getT(),
209
207
  t = _getT.t;
210
208
  return {
211
209
  t: t,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vtx/modals2",
3
- "version": "6.0.0-beta.0",
3
+ "version": "6.0.0-beta.1",
4
4
  "description": "弹窗组件",
5
5
  "license": "MIT",
6
6
  "module": "lib/index.js",