@chaoswise/business 1.0.5 → 2.1.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/lib/I18nInput/index.d.ts +31 -0
- package/lib/I18nInput/index.js +379 -0
- package/lib/I18nInput/index.less +7 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -4
- package/lib/locales/en_US.json +1 -1
- package/lib/locales/index.d.ts +7 -0
- package/lib/locales/index.js +28 -13
- package/lib/locales/intl.d.ts +11 -0
- package/lib/locales/intl.js +39 -24
- package/lib/locales/ja_JP.json +1 -0
- package/lib/locales/normalizeLocale.d.ts +2 -0
- package/lib/locales/normalizeLocale.js +27 -0
- package/lib/locales/withLocale.d.ts +28 -0
- package/lib/locales/withLocale.js +2 -2
- package/lib/locales/zh_CN.json +1 -1
- package/lib/locales/zh_HK.json +1 -0
- package/lib/locales/zh_TW.json +1 -1
- package/package.json +10 -5
- package/lib/AggregateSearch/CLSPL/CLQLLexer.js +0 -78
- package/lib/AggregateSearch/CLSPL/CLQLParser.js +0 -2724
- package/lib/AggregateSearch/CLSPL/CLQLParserListener.js +0 -347
- package/lib/AggregateSearch/CLSPL/CLQLParserVisitor.js +0 -251
- package/lib/AggregateSearch/CLSPL/SPLStagy.js +0 -197
- package/lib/AggregateSearch/CLSPL/index.js +0 -196
- package/lib/AggregateSearch/CLSPL/makeTokenizeFn.js +0 -18
- package/lib/AggregateSearch/CLSPL/token.js +0 -7
- package/lib/AggregateSearch/components/CloseAllIcon/index.js +0 -13
- package/lib/AggregateSearch/components/CloseAllIcon/index.less +0 -11
- package/lib/AggregateSearch/components/DropDown/assets/combined.svg +0 -22
- package/lib/AggregateSearch/components/DropDown/assets/copy.svg +0 -22
- package/lib/AggregateSearch/components/DropDown/assets/delete.svg +0 -24
- package/lib/AggregateSearch/components/DropDown/assets/home.svg +0 -20
- package/lib/AggregateSearch/components/DropDown/assets/key.svg +0 -21
- package/lib/AggregateSearch/components/DropDown/assets/star.svg +0 -22
- package/lib/AggregateSearch/components/DropDown/assets/time-circle.svg +0 -20
- package/lib/AggregateSearch/components/DropDown/assets/value.svg +0 -23
- package/lib/AggregateSearch/components/DropDown/config.js +0 -54
- package/lib/AggregateSearch/components/DropDown/index.js +0 -584
- package/lib/AggregateSearch/components/DropDown/index.less +0 -118
- package/lib/AggregateSearch/components/SwitchBtn/assets/tag-icon.svg +0 -17
- package/lib/AggregateSearch/components/SwitchBtn/assets/text-icon.svg +0 -18
- package/lib/AggregateSearch/components/SwitchBtn/index.js +0 -27
- package/lib/AggregateSearch/components/SwitchBtn/index.less +0 -31
- package/lib/AggregateSearch/hooks/useDropDown.js +0 -428
- package/lib/AggregateSearch/index.js +0 -520
- package/lib/AggregateSearch/index.less +0 -225
- package/lib/AggregateSearch/utils/index.js +0 -391
- package/lib/ContentEditableSearch/components/CloseAllIcon/index.js +0 -13
- package/lib/ContentEditableSearch/components/CloseAllIcon/index.less +0 -11
- package/lib/ContentEditableSearch/index.js +0 -157
- package/lib/ContentEditableSearch/index.less +0 -65
- package/lib/ContentEditableSearch/utils/index.js +0 -98
- package/lib/PropertyControlViewer/assets/doCommon.less +0 -75
- package/lib/PropertyControlViewer/assets/doSelect.less +0 -74
- package/lib/PropertyControlViewer/assets/index.less +0 -189
- package/lib/PropertyControlViewer/components/DoAppIcon/CustomIcon/iconfont.js +0 -1
- package/lib/PropertyControlViewer/components/DoAppIcon/CustomIcon/index.js +0 -29
- package/lib/PropertyControlViewer/components/DoAppIcon/iconData/IconJson.js +0 -0
- package/lib/PropertyControlViewer/components/DoAppIcon/index.js +0 -41
- package/lib/PropertyControlViewer/components/DoCiUnitBitmap.js +0 -50
- package/lib/PropertyControlViewer/components/DoCommon.js +0 -36
- package/lib/PropertyControlViewer/components/DoDefaultPlaceholder.js +0 -9
- package/lib/PropertyControlViewer/components/DoImage.js +0 -107
- package/lib/PropertyControlViewer/components/DoQuote/components/QuoteView.js +0 -63
- package/lib/PropertyControlViewer/components/DoQuote/components/TableQuoteView.js +0 -18
- package/lib/PropertyControlViewer/components/DoQuote/index.js +0 -16
- package/lib/PropertyControlViewer/components/DoSelect.js +0 -80
- package/lib/PropertyControlViewer/components/DoTable.js +0 -44
- package/lib/PropertyControlViewer/components/DoUser.js +0 -61
- package/lib/PropertyControlViewer/components/TagShowMoreList/index.js +0 -132
- package/lib/PropertyControlViewer/components/TagShowMoreList/index.less +0 -106
- package/lib/PropertyControlViewer/config/constants.js +0 -84
- package/lib/PropertyControlViewer/config/utils.js +0 -353
- package/lib/PropertyControlViewer/index.js +0 -195
- package/lib/PropertyControlViewer/index.less +0 -107
- package/lib/Watermark/index.js +0 -187
- package/lib/Watermark/index.less +0 -17
- package/lib/demo.js +0 -0
- package/lib/locale/en_US.js +0 -9
- package/lib/locale/index.js +0 -12
- package/lib/locale/zh_CN.js +0 -9
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export default I18nInput;
|
|
2
|
+
declare function I18nInput(props: any): React.JSX.Element;
|
|
3
|
+
declare namespace I18nInput {
|
|
4
|
+
namespace propTypes {
|
|
5
|
+
const value: PropTypes.Requireable<NonNullable<string | object>>;
|
|
6
|
+
const onChange: PropTypes.Requireable<(...args: any[]) => any>;
|
|
7
|
+
const placeholder: PropTypes.Requireable<string>;
|
|
8
|
+
const maxLength: PropTypes.Requireable<number>;
|
|
9
|
+
const allowClear: PropTypes.Requireable<boolean>;
|
|
10
|
+
const onSyncChange: PropTypes.Requireable<(...args: any[]) => any>;
|
|
11
|
+
const i18nValue: PropTypes.Requireable<object>;
|
|
12
|
+
const locale: PropTypes.Validator<string>;
|
|
13
|
+
const language: PropTypes.Requireable<PropTypes.InferProps<{
|
|
14
|
+
value: PropTypes.Validator<string>;
|
|
15
|
+
name: PropTypes.Requireable<string>;
|
|
16
|
+
}>[]>;
|
|
17
|
+
const drawerProps: PropTypes.Requireable<object>;
|
|
18
|
+
const formProps: PropTypes.Requireable<object>;
|
|
19
|
+
const enableI18n: PropTypes.Requireable<boolean>;
|
|
20
|
+
const required: PropTypes.Requireable<boolean>;
|
|
21
|
+
const requiredLocales: PropTypes.Requireable<{
|
|
22
|
+
[x: string]: boolean;
|
|
23
|
+
}>;
|
|
24
|
+
const requiredMessage: PropTypes.Requireable<string>;
|
|
25
|
+
const rules: PropTypes.Requireable<NonNullable<object[] | {
|
|
26
|
+
[x: string]: object[];
|
|
27
|
+
}>>;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
import React from "react";
|
|
31
|
+
import PropTypes from "prop-types";
|
|
@@ -0,0 +1,379 @@
|
|
|
1
|
+
import _Empty from "@chaoswise/ui/lib/Empty";
|
|
2
|
+
import _CustomScrollBar from "@chaoswise/ui/lib/CustomScrollBar";
|
|
3
|
+
import _Button from "@chaoswise/ui/lib/Button";
|
|
4
|
+
import _Space from "@chaoswise/ui/lib/Space";
|
|
5
|
+
import _Drawer from "@chaoswise/ui/lib/Drawer";
|
|
6
|
+
import _Input from "@chaoswise/ui/lib/Input";
|
|
7
|
+
import _Form from "@chaoswise/ui/lib/Form";
|
|
8
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
9
|
+
function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i["return"]) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
|
|
10
|
+
function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, _regeneratorDefine2(e, r, n, t); }
|
|
11
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
12
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
13
|
+
function _toPrimitive(t, e) { if ("object" != _typeof(t) || !t) return t; var r; if ("undefined" != typeof Symbol && void 0 !== (r = t[Symbol.toPrimitive])) { var i = r.call(t, e || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === e ? String : Number)(t); }
|
|
14
|
+
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
15
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
16
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
17
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
18
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
19
|
+
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
20
|
+
var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, generator) {
|
|
21
|
+
function adopt(value) {
|
|
22
|
+
return value instanceof P ? value : new P(function (resolve) {
|
|
23
|
+
resolve(value);
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
27
|
+
function fulfilled(value) {
|
|
28
|
+
try {
|
|
29
|
+
step(generator.next(value));
|
|
30
|
+
} catch (e) {
|
|
31
|
+
reject(e);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function rejected(value) {
|
|
35
|
+
try {
|
|
36
|
+
step(generator["throw"](value));
|
|
37
|
+
} catch (e) {
|
|
38
|
+
reject(e);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function step(result) {
|
|
42
|
+
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
43
|
+
}
|
|
44
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
var __rest = this && this.__rest || function (s, e) {
|
|
48
|
+
var t = {};
|
|
49
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
|
|
50
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
51
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
|
|
52
|
+
}
|
|
53
|
+
return t;
|
|
54
|
+
};
|
|
55
|
+
import React, { useState } from 'react';
|
|
56
|
+
import PropTypes from 'prop-types';
|
|
57
|
+
import { International } from '@icon-park/react';
|
|
58
|
+
import { useIntl } from '../locales';
|
|
59
|
+
import { normalizeLocale, normalizeLocaleRecord } from '../locales/normalizeLocale';
|
|
60
|
+
import './index.less';
|
|
61
|
+
var I18nInput = function I18nInput(props) {
|
|
62
|
+
var intl = useIntl();
|
|
63
|
+
var inputValue = props.value,
|
|
64
|
+
onChange = props.onChange,
|
|
65
|
+
placeholder = props.placeholder,
|
|
66
|
+
_props$maxLength = props.maxLength,
|
|
67
|
+
maxLength = _props$maxLength === void 0 ? 40 : _props$maxLength,
|
|
68
|
+
_props$allowClear = props.allowClear,
|
|
69
|
+
allowClear = _props$allowClear === void 0 ? true : _props$allowClear,
|
|
70
|
+
onSyncChange = props.onSyncChange,
|
|
71
|
+
inputI18nValue = props.i18nValue,
|
|
72
|
+
inputLocale = props.locale,
|
|
73
|
+
_props$language = props.language,
|
|
74
|
+
inputLanguage = _props$language === void 0 ? [] : _props$language,
|
|
75
|
+
inputRequiredLocales = props.requiredLocales,
|
|
76
|
+
inputRules = props.rules,
|
|
77
|
+
drawerProps = props.drawerProps,
|
|
78
|
+
formProps = props.formProps,
|
|
79
|
+
_props$enableI18n = props.enableI18n,
|
|
80
|
+
enableI18n = _props$enableI18n === void 0 ? true : _props$enableI18n,
|
|
81
|
+
restProps = __rest(props, ["value", "onChange", "placeholder", "maxLength", "allowClear", "onSyncChange", "i18nValue", "locale", "language", "requiredLocales", "rules", "drawerProps", "formProps", "enableI18n"]);
|
|
82
|
+
var locale = normalizeLocale(inputLocale);
|
|
83
|
+
var _useState = useState(false),
|
|
84
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
85
|
+
drawerVisible = _useState2[0],
|
|
86
|
+
setDrawerVisible = _useState2[1];
|
|
87
|
+
var _Form$useForm = _Form.useForm(),
|
|
88
|
+
_Form$useForm2 = _slicedToArray(_Form$useForm, 1),
|
|
89
|
+
drawerForm = _Form$useForm2[0];
|
|
90
|
+
var isDisabled = restProps.disabled || restProps.readOnly;
|
|
91
|
+
var isSyncMode = !!onSyncChange;
|
|
92
|
+
var value = isSyncMode ? inputValue : normalizeLocaleRecord(inputValue);
|
|
93
|
+
var i18nValue = normalizeLocaleRecord(inputI18nValue);
|
|
94
|
+
var requiredLocales = normalizeLocaleRecord(inputRequiredLocales);
|
|
95
|
+
var rules = normalizeLocaleRecord(inputRules);
|
|
96
|
+
var language = inputLanguage.map(function (lang) {
|
|
97
|
+
return Object.assign(Object.assign({}, lang), {
|
|
98
|
+
value: normalizeLocale(lang.value)
|
|
99
|
+
});
|
|
100
|
+
}).filter(function (lang, index, list) {
|
|
101
|
+
return list.findIndex(function (item) {
|
|
102
|
+
return item.value === lang.value;
|
|
103
|
+
}) === index;
|
|
104
|
+
});
|
|
105
|
+
var getDisplayValue = function getDisplayValue() {
|
|
106
|
+
if (isSyncMode) {
|
|
107
|
+
return value || '';
|
|
108
|
+
}
|
|
109
|
+
var i18nValueObj = value || {};
|
|
110
|
+
if (i18nValueObj[locale]) return i18nValueObj[locale];
|
|
111
|
+
var fallbackOrder = ['zh_CN', 'en_US', 'zh_TW'];
|
|
112
|
+
for (var _i = 0, _fallbackOrder = fallbackOrder; _i < _fallbackOrder.length; _i++) {
|
|
113
|
+
var lang = _fallbackOrder[_i];
|
|
114
|
+
if (i18nValueObj[lang]) return i18nValueObj[lang];
|
|
115
|
+
}
|
|
116
|
+
var values = Object.values(i18nValueObj);
|
|
117
|
+
return values.find(function (v) {
|
|
118
|
+
return v;
|
|
119
|
+
}) || '';
|
|
120
|
+
};
|
|
121
|
+
var handleInputChange = function handleInputChange(e) {
|
|
122
|
+
var inputValue = e.target.value;
|
|
123
|
+
if (isSyncMode) {
|
|
124
|
+
var currentI18nValue = i18nValue || {};
|
|
125
|
+
var newI18nValue = Object.assign(Object.assign({}, currentI18nValue), _defineProperty({}, locale, inputValue));
|
|
126
|
+
if (onSyncChange) {
|
|
127
|
+
onSyncChange(inputValue, newI18nValue);
|
|
128
|
+
}
|
|
129
|
+
if (onChange) {
|
|
130
|
+
onChange(inputValue);
|
|
131
|
+
}
|
|
132
|
+
} else {
|
|
133
|
+
var _newI18nValue = Object.assign(Object.assign({}, value || {}), _defineProperty({}, locale, inputValue));
|
|
134
|
+
if (onChange) {
|
|
135
|
+
onChange(_newI18nValue);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
var handleIconClick = function handleIconClick() {
|
|
140
|
+
if (isDisabled) return;
|
|
141
|
+
var initialValues = {};
|
|
142
|
+
if (isSyncMode) {
|
|
143
|
+
var currentI18nValue = i18nValue || {};
|
|
144
|
+
var currentValue = value || '';
|
|
145
|
+
initialValues = Object.assign(Object.assign({}, currentI18nValue), _defineProperty({}, locale, currentValue));
|
|
146
|
+
} else {
|
|
147
|
+
initialValues = value || {};
|
|
148
|
+
}
|
|
149
|
+
drawerForm.setFieldsValue(initialValues);
|
|
150
|
+
setDrawerVisible(true);
|
|
151
|
+
};
|
|
152
|
+
var handleConfirm = function handleConfirm() {
|
|
153
|
+
return __awaiter(void 0, void 0, void 0, /*#__PURE__*/_regenerator().m(function _callee() {
|
|
154
|
+
var formValues, currentValue, _t, _t2;
|
|
155
|
+
return _regenerator().w(function (_context) {
|
|
156
|
+
while (1) switch (_context.p = _context.n) {
|
|
157
|
+
case 0:
|
|
158
|
+
_context.p = 0;
|
|
159
|
+
_t = normalizeLocaleRecord;
|
|
160
|
+
_context.n = 1;
|
|
161
|
+
return drawerForm.validateFields();
|
|
162
|
+
case 1:
|
|
163
|
+
formValues = _t(_context.v);
|
|
164
|
+
currentValue = formValues[locale] || '';
|
|
165
|
+
if (isSyncMode) {
|
|
166
|
+
if (onSyncChange) {
|
|
167
|
+
onSyncChange(currentValue, formValues);
|
|
168
|
+
}
|
|
169
|
+
if (onChange) {
|
|
170
|
+
onChange(currentValue);
|
|
171
|
+
}
|
|
172
|
+
} else {
|
|
173
|
+
if (onChange) {
|
|
174
|
+
onChange(formValues);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
setDrawerVisible(false);
|
|
178
|
+
_context.n = 3;
|
|
179
|
+
break;
|
|
180
|
+
case 2:
|
|
181
|
+
_context.p = 2;
|
|
182
|
+
_t2 = _context.v;
|
|
183
|
+
case 3:
|
|
184
|
+
return _context.a(2);
|
|
185
|
+
}
|
|
186
|
+
}, _callee, null, [[0, 2]]);
|
|
187
|
+
}));
|
|
188
|
+
};
|
|
189
|
+
var handleCancel = function handleCancel() {
|
|
190
|
+
var initialValues = {};
|
|
191
|
+
if (isSyncMode) {
|
|
192
|
+
var currentI18nValue = i18nValue || {};
|
|
193
|
+
var currentValue = value || '';
|
|
194
|
+
initialValues = Object.assign(Object.assign({}, currentI18nValue), _defineProperty({}, locale, currentValue));
|
|
195
|
+
} else {
|
|
196
|
+
initialValues = value || {};
|
|
197
|
+
}
|
|
198
|
+
drawerForm.setFieldsValue(initialValues);
|
|
199
|
+
setDrawerVisible(false);
|
|
200
|
+
};
|
|
201
|
+
var getLanguageName = function getLanguageName(lang) {
|
|
202
|
+
return lang.name || lang.value;
|
|
203
|
+
};
|
|
204
|
+
var getRules = function getRules(langValue) {
|
|
205
|
+
var required = props.required,
|
|
206
|
+
requiredMessage = props.requiredMessage;
|
|
207
|
+
// rules 对象:按语言返回对应规则
|
|
208
|
+
if (rules && _typeof(rules) === 'object' && !Array.isArray(rules)) {
|
|
209
|
+
return rules[langValue] || [];
|
|
210
|
+
}
|
|
211
|
+
// rules 数组:统一应用所有语言
|
|
212
|
+
if (Array.isArray(rules) && rules.length > 0) {
|
|
213
|
+
return rules;
|
|
214
|
+
}
|
|
215
|
+
// 判断是否必填
|
|
216
|
+
var isRequired = false;
|
|
217
|
+
if (requiredLocales) {
|
|
218
|
+
isRequired = requiredLocales[langValue] === true;
|
|
219
|
+
} else if (required !== undefined) {
|
|
220
|
+
isRequired = required;
|
|
221
|
+
} else {
|
|
222
|
+
isRequired = langValue === locale; // 默认:仅当前语言必填
|
|
223
|
+
}
|
|
224
|
+
if (!isRequired) return [];
|
|
225
|
+
// 返回必填规则
|
|
226
|
+
return [{
|
|
227
|
+
required: true,
|
|
228
|
+
whitespace: true,
|
|
229
|
+
message: requiredMessage || intl.get('99b301b7-f153-4861-8ca3-22371b6b95d9').d('请输入')
|
|
230
|
+
}];
|
|
231
|
+
};
|
|
232
|
+
var drawerTitle = intl.get('e25f1462-c823-434a-a6b2-4258dd57930a').d('多语言配置');
|
|
233
|
+
var confirmText = intl.get('632edd96-893f-4599-b1a3-0406e2146010').d('确定');
|
|
234
|
+
var cancelText = intl.get('19d6c313-9540-4042-b642-ebc6396ca0c7').d('取消');
|
|
235
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(_Input, Object.assign({
|
|
236
|
+
value: getDisplayValue(),
|
|
237
|
+
onChange: handleInputChange,
|
|
238
|
+
placeholder: placeholder,
|
|
239
|
+
addonAfter: enableI18n ? (/*#__PURE__*/React.createElement(International, {
|
|
240
|
+
style: {
|
|
241
|
+
display: 'flex',
|
|
242
|
+
alignItems: 'center',
|
|
243
|
+
cursor: isDisabled ? 'not-allowed' : 'pointer',
|
|
244
|
+
opacity: isDisabled ? 0.5 : 1
|
|
245
|
+
},
|
|
246
|
+
theme: 'outline',
|
|
247
|
+
size: '16',
|
|
248
|
+
fill: '#333',
|
|
249
|
+
onClick: handleIconClick
|
|
250
|
+
})) : null
|
|
251
|
+
}, restProps)), /*#__PURE__*/React.createElement(_Drawer, Object.assign({
|
|
252
|
+
visible: drawerVisible,
|
|
253
|
+
onClose: handleCancel,
|
|
254
|
+
title: drawerTitle,
|
|
255
|
+
width: 500,
|
|
256
|
+
destroyOnClose: true,
|
|
257
|
+
maskClosable: false,
|
|
258
|
+
footer: /*#__PURE__*/React.createElement(_Space, null, /*#__PURE__*/React.createElement(_Button, {
|
|
259
|
+
mainType: true,
|
|
260
|
+
type: 'primary',
|
|
261
|
+
onClick: handleConfirm
|
|
262
|
+
}, confirmText), /*#__PURE__*/React.createElement(_Button, {
|
|
263
|
+
mainType: true,
|
|
264
|
+
onClick: handleCancel
|
|
265
|
+
}, cancelText))
|
|
266
|
+
}, drawerProps), /*#__PURE__*/React.createElement(_CustomScrollBar, null, /*#__PURE__*/React.createElement(_Form, Object.assign({
|
|
267
|
+
form: drawerForm,
|
|
268
|
+
labelCol: {
|
|
269
|
+
span: 6
|
|
270
|
+
},
|
|
271
|
+
wrapperCol: {
|
|
272
|
+
span: 18
|
|
273
|
+
},
|
|
274
|
+
labelAlign: 'left',
|
|
275
|
+
colon: true
|
|
276
|
+
}, formProps), language.length > 0 ? language.map(function (lang) {
|
|
277
|
+
return /*#__PURE__*/React.createElement(_Form.Item, {
|
|
278
|
+
key: lang.value,
|
|
279
|
+
name: lang.value,
|
|
280
|
+
label: getLanguageName(lang),
|
|
281
|
+
className: 'languageItem',
|
|
282
|
+
rules: getRules(lang.value)
|
|
283
|
+
}, /*#__PURE__*/React.createElement(_Input, {
|
|
284
|
+
maxLength: maxLength,
|
|
285
|
+
showCount: true,
|
|
286
|
+
allowClear: allowClear
|
|
287
|
+
}));
|
|
288
|
+
}) : (/*#__PURE__*/React.createElement(_Empty, null))))));
|
|
289
|
+
};
|
|
290
|
+
I18nInput.propTypes = {
|
|
291
|
+
/**
|
|
292
|
+
* 受控值,多语言模式下为对象 {zh_CN: '中文', en_US: 'English'},同步模式下为字符串
|
|
293
|
+
*/
|
|
294
|
+
value: PropTypes.oneOfType([PropTypes.string, PropTypes.object]),
|
|
295
|
+
/**
|
|
296
|
+
* 值变化的回调函数
|
|
297
|
+
* 多语言模式:(value: Record<string, string>) => {}
|
|
298
|
+
* 同步模式:(value: string) => {}
|
|
299
|
+
*/
|
|
300
|
+
onChange: PropTypes.func,
|
|
301
|
+
/**
|
|
302
|
+
* 输入框占位符
|
|
303
|
+
*/
|
|
304
|
+
placeholder: PropTypes.string,
|
|
305
|
+
/**
|
|
306
|
+
* 最大输入长度,默认为 40
|
|
307
|
+
*/
|
|
308
|
+
maxLength: PropTypes.number,
|
|
309
|
+
/**
|
|
310
|
+
* 是否允许清除,默认为 true
|
|
311
|
+
*/
|
|
312
|
+
allowClear: PropTypes.bool,
|
|
313
|
+
/**
|
|
314
|
+
* 同步模式下的回调函数,当输入框值变化时同时更新同步值和多语言值
|
|
315
|
+
* (syncValue: string, i18nValue: Record<string, string>) => {}
|
|
316
|
+
*/
|
|
317
|
+
onSyncChange: PropTypes.func,
|
|
318
|
+
/**
|
|
319
|
+
* 同步模式下的多语言值对象
|
|
320
|
+
*/
|
|
321
|
+
i18nValue: PropTypes.object,
|
|
322
|
+
/**
|
|
323
|
+
* 当前语言环境,如 'zh_CN'、'en_US'、'zh_TW'、'zh_HK';兼容连字符别名。
|
|
324
|
+
* 多语言数据、language 和规则键同步规范化,回调统一返回下划线键;标准键优先。
|
|
325
|
+
*/
|
|
326
|
+
locale: PropTypes.string.isRequired,
|
|
327
|
+
/**
|
|
328
|
+
* 支持的语言列表
|
|
329
|
+
* [{ value: 'zh_CN', name: '简体中文' }, { value: 'en_US', name: 'English' }]
|
|
330
|
+
*/
|
|
331
|
+
language: PropTypes.arrayOf(PropTypes.shape({
|
|
332
|
+
value: PropTypes.string.isRequired,
|
|
333
|
+
name: PropTypes.string
|
|
334
|
+
})),
|
|
335
|
+
/**
|
|
336
|
+
* Drawer 组件的额外属性配置
|
|
337
|
+
*/
|
|
338
|
+
drawerProps: PropTypes.object,
|
|
339
|
+
/**
|
|
340
|
+
* Form 组件的额外属性配置
|
|
341
|
+
*/
|
|
342
|
+
formProps: PropTypes.object,
|
|
343
|
+
/**
|
|
344
|
+
* 是否启用国际化功能,默认为 true
|
|
345
|
+
* 当设置为 false 时,不显示国际化图标
|
|
346
|
+
*/
|
|
347
|
+
enableI18n: PropTypes.bool,
|
|
348
|
+
/**
|
|
349
|
+
* 是否必填,默认情况下只有当前语言(locale)必填
|
|
350
|
+
* - undefined: 默认行为,当前语言必填,其他非必填
|
|
351
|
+
* - true: 所有语言项必填
|
|
352
|
+
* - false: 所有语言项非必填
|
|
353
|
+
*/
|
|
354
|
+
required: PropTypes.bool,
|
|
355
|
+
/**
|
|
356
|
+
* 指定哪些语言必填,优先级高于 required
|
|
357
|
+
* 例如:{ zh_CN: true, en_US: false, zh_TW: true }
|
|
358
|
+
*/
|
|
359
|
+
requiredLocales: PropTypes.objectOf(PropTypes.bool),
|
|
360
|
+
/**
|
|
361
|
+
* 自定义必填错误提示消息
|
|
362
|
+
*/
|
|
363
|
+
requiredMessage: PropTypes.string,
|
|
364
|
+
/**
|
|
365
|
+
* 完全自定义校验规则,优先级最高
|
|
366
|
+
* 支持两种格式:
|
|
367
|
+
* 1. 数组格式:统一应用到所有语言项
|
|
368
|
+
* [{ required: true, message: '请输入' }, { max: 50, message: '最多50个字符' }]
|
|
369
|
+
* 2. 对象格式:为每种语言指定不同规则
|
|
370
|
+
* {
|
|
371
|
+
* zh_CN: [{ required: true, message: '请输入中文' }],
|
|
372
|
+
* en_US: [{ required: true, max: 100, message: 'Required' }],
|
|
373
|
+
* zh_TW: [{ max: 50, message: '最多50個字符' }],
|
|
374
|
+
* ja_JP: [] // 日语非必填
|
|
375
|
+
* }
|
|
376
|
+
*/
|
|
377
|
+
rules: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.object), PropTypes.objectOf(PropTypes.arrayOf(PropTypes.object))])
|
|
378
|
+
};
|
|
379
|
+
export default I18nInput;
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as I18nInput } from "./I18nInput";
|
package/lib/index.js
CHANGED
|
@@ -1,4 +1 @@
|
|
|
1
|
-
export { default as
|
|
2
|
-
export { default as AggregateSearch } from "./AggregateSearch";
|
|
3
|
-
export { default as Watermark } from "./Watermark";
|
|
4
|
-
export { default as ContentEditableSearch } from "./ContentEditableSearch";
|
|
1
|
+
export { default as I18nInput } from "./I18nInput";
|
package/lib/locales/en_US.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"
|
|
1
|
+
{"19d6c313-9540-4042-b642-ebc6396ca0c7":"Cancel","632edd96-893f-4599-b1a3-0406e2146010":"Confirm","99b301b7-f153-4861-8ca3-22371b6b95d9":"Please enter","e25f1462-c823-434a-a6b2-4258dd57930a":"Multi-language Configuration"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export function useIntl(): import("react-intl-universal/lib/ReactIntlUniversal").default;
|
|
2
|
+
export default intl;
|
|
3
|
+
import { TagInitInstance } from "./intl";
|
|
4
|
+
import { useForceUpdate } from "./intl";
|
|
5
|
+
import withLocale from "./withLocale";
|
|
6
|
+
import intl from "./intl";
|
|
7
|
+
export { TagInitInstance, useForceUpdate, withLocale };
|
package/lib/locales/index.js
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
2
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
3
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
4
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
5
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
6
|
+
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
7
|
+
import { useEffect, useContext, useMemo, useState } from "react";
|
|
2
8
|
import intl, { useForceUpdate, TagInitInstance, injectLocale } from "./intl";
|
|
3
9
|
import { intlContext } from '@chaoswise/ui/lib/ConfigProvider/ConfigProvider';
|
|
4
10
|
import withLocale from "./withLocale";
|
|
5
|
-
|
|
11
|
+
import { normalizeLocale } from './normalizeLocale';
|
|
6
12
|
// 初始化默认值取消warning
|
|
7
13
|
intl.init({
|
|
8
14
|
currentLocale: 'default',
|
|
@@ -11,32 +17,41 @@ intl.init({
|
|
|
11
17
|
return null;
|
|
12
18
|
}
|
|
13
19
|
});
|
|
14
|
-
|
|
15
20
|
// 导出TagInitInstance
|
|
16
21
|
export { TagInitInstance, useForceUpdate, withLocale };
|
|
17
22
|
export var useIntl = function useIntl() {
|
|
18
23
|
var _useContext = useContext(intlContext),
|
|
19
24
|
locale = _useContext.locale;
|
|
20
|
-
|
|
21
|
-
// 兼容映射
|
|
22
25
|
var currentLocale = useMemo(function () {
|
|
23
|
-
|
|
24
|
-
zh: "zh_CN",
|
|
25
|
-
en: "en_US"
|
|
26
|
-
};
|
|
27
|
-
return map[locale] || locale;
|
|
26
|
+
return normalizeLocale(locale);
|
|
28
27
|
}, [locale]);
|
|
29
28
|
var forceUpdate = useForceUpdate();
|
|
29
|
+
var _useState = useState(null),
|
|
30
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
31
|
+
failure = _useState2[0],
|
|
32
|
+
setFailure = _useState2[1];
|
|
30
33
|
useEffect(function () {
|
|
31
34
|
// 有组件注册过就不再注册
|
|
32
35
|
if (TagInitInstance.getCurrentLocale() === currentLocale) {
|
|
33
36
|
return;
|
|
34
37
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
+
var active = true;
|
|
39
|
+
injectLocale(currentLocale, function (loadedLocale) {
|
|
40
|
+
TagInitInstance.setCurrentLocale(loadedLocale);
|
|
41
|
+
if (active) forceUpdate();
|
|
42
|
+
})["catch"](function (error) {
|
|
43
|
+
if (active) setFailure({
|
|
44
|
+
locale: currentLocale,
|
|
45
|
+
error: error
|
|
46
|
+
});
|
|
38
47
|
});
|
|
48
|
+
return function () {
|
|
49
|
+
active = false;
|
|
50
|
+
};
|
|
39
51
|
}, [currentLocale]);
|
|
52
|
+
if (failure && failure.locale === currentLocale) {
|
|
53
|
+
throw failure.error;
|
|
54
|
+
}
|
|
40
55
|
return intl;
|
|
41
56
|
};
|
|
42
57
|
export default intl;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export function useForceUpdate(): () => void;
|
|
2
|
+
export function injectLocale(currentLocale: any, cb?: () => void): any;
|
|
3
|
+
export const TagInitInstance: TagInit;
|
|
4
|
+
export default IntlInstance;
|
|
5
|
+
declare class TagInit {
|
|
6
|
+
currentLocale: string;
|
|
7
|
+
setCurrentLocale(currentLocale: any): void;
|
|
8
|
+
getCurrentLocale(): string;
|
|
9
|
+
}
|
|
10
|
+
declare const IntlInstance: ReactIntlUniversal;
|
|
11
|
+
import { ReactIntlUniversal } from "react-intl-universal";
|
package/lib/locales/intl.js
CHANGED
|
@@ -4,7 +4,7 @@ function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Can
|
|
|
4
4
|
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
|
|
5
5
|
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
6
6
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
7
|
-
function _toPrimitive(t,
|
|
7
|
+
function _toPrimitive(t, e) { if ("object" != _typeof(t) || !t) return t; var r; if ("undefined" != typeof Symbol && void 0 !== (r = t[Symbol.toPrimitive])) { var i = r.call(t, e || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === e ? String : Number)(t); }
|
|
8
8
|
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
9
9
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
10
10
|
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
@@ -12,6 +12,7 @@ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length)
|
|
|
12
12
|
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
13
13
|
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
14
14
|
import { useCallback, useState } from 'react';
|
|
15
|
+
import { normalizeLocale } from './normalizeLocale';
|
|
15
16
|
import { ReactIntlUniversal } from 'react-intl-universal';
|
|
16
17
|
var IntlInstance = new ReactIntlUniversal();
|
|
17
18
|
var createNewObject = function createNewObject() {
|
|
@@ -42,33 +43,47 @@ var TagInit = /*#__PURE__*/function () {
|
|
|
42
43
|
return this.currentLocale;
|
|
43
44
|
}
|
|
44
45
|
}]);
|
|
45
|
-
}();
|
|
46
|
+
}(); // 支持范围独立于格式规范化。平台资源由构建工具收集为异步模块。
|
|
47
|
+
var supportedLocales = ['zh_CN', 'en_US', 'zh_TW', 'zh_HK', 'ja_JP'];
|
|
48
|
+
var loadLocaleFile = function loadLocaleFile(locale) {
|
|
49
|
+
return import("./".concat(locale, ".json"));
|
|
50
|
+
};
|
|
51
|
+
// 默认语言(不支持的语言时回退到此)
|
|
52
|
+
var DEFAULT_LOCALE = 'zh_CN';
|
|
46
53
|
export var injectLocale = function injectLocale(currentLocale) {
|
|
47
54
|
var cb = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function () {};
|
|
48
|
-
var initFunc = function initFunc(
|
|
49
|
-
IntlInstance.init({
|
|
50
|
-
currentLocale:
|
|
51
|
-
locales: _defineProperty({},
|
|
55
|
+
var initFunc = function initFunc(locale, data) {
|
|
56
|
+
return IntlInstance.init({
|
|
57
|
+
currentLocale: locale,
|
|
58
|
+
locales: _defineProperty({}, locale, data)
|
|
52
59
|
});
|
|
53
60
|
};
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
61
|
+
// 加载语言文件的函数
|
|
62
|
+
var _loadLocale = function loadLocale(locale) {
|
|
63
|
+
if (supportedLocales.includes(locale)) {
|
|
64
|
+
return loadLocaleFile(locale).then(function (res) {
|
|
65
|
+
return initFunc(locale, res["default"]);
|
|
66
|
+
}).then(function () {
|
|
67
|
+
cb(locale);
|
|
68
|
+
return locale;
|
|
69
|
+
})["catch"](function (error) {
|
|
70
|
+
console.warn("Failed to load locale file for ".concat(locale, ":"), error);
|
|
71
|
+
// 繁体资源缺失不可伪装成简体初始化成功。
|
|
72
|
+
if (locale === 'zh_HK' || locale === 'zh_TW') {
|
|
73
|
+
throw error;
|
|
74
|
+
}
|
|
75
|
+
if (locale !== DEFAULT_LOCALE) {
|
|
76
|
+
return _loadLocale(DEFAULT_LOCALE);
|
|
77
|
+
}
|
|
78
|
+
throw error;
|
|
79
|
+
});
|
|
80
|
+
} else {
|
|
81
|
+
// 如果语言不支持,回退到默认语言(中文)
|
|
82
|
+
console.warn("Locale ".concat(locale, " is not supported, falling back to ").concat(DEFAULT_LOCALE));
|
|
83
|
+
return _loadLocale(DEFAULT_LOCALE);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
return _loadLocale(normalizeLocale(currentLocale));
|
|
72
87
|
};
|
|
73
88
|
export var TagInitInstance = new TagInit();
|
|
74
89
|
export default IntlInstance;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"19d6c313-9540-4042-b642-ebc6396ca0c7":"キャンセル","632edd96-893f-4599-b1a3-0406e2146010":"確認","99b301b7-f153-4861-8ca3-22371b6b95d9":"入力してください","e25f1462-c823-434a-a6b2-4258dd57930a":"多言語設定"}
|