@tddc/assign-modal 3.1.2 → 3.1.4
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/README.md +0 -4
- package/es/AssignModal/AssignApp/Edit.js +1 -1
- package/es/AssignModal/AssignApp/View.js +1 -1
- package/es/AssignModal/AssignApp/index.less +1 -0
- package/es/AssignModal/index.js +58 -34
- package/es/{locale.js → I18N.js} +29 -51
- package/es/locale/ar-EG.js +4 -0
- package/es/locale/en-US.js +0 -0
- package/es/locale/es-ES.js +0 -0
- package/es/locale/ko-KR.js +0 -0
- package/es/locale/th-TH.js +0 -0
- package/es/locale/zh-CN.js +0 -0
- package/package.json +2 -2
- package/src/.octopus/ar-EG/index.js +5 -0
- package/src/.octopus/ar-EG/test.js +3 -0
- package/src/.octopus/en-US/index.js +19 -0
- package/src/.octopus/en-US/test.js +3 -0
- package/src/.octopus/es-ES/index.js +5 -0
- package/src/.octopus/es-ES/test.js +3 -0
- package/src/.octopus/ko-KR/index.js +5 -0
- package/src/.octopus/ko-KR/test.js +3 -0
- package/src/.octopus/th-TH/index.js +5 -0
- package/src/.octopus/th-TH/test.js +3 -0
- package/src/.octopus/zh-CN/index.js +19 -0
- package/src/AssignModal/AssignApp/Edit.js +1 -1
- package/src/AssignModal/AssignApp/View.js +1 -1
- package/src/AssignModal/AssignApp/index.less +1 -0
- package/src/AssignModal/index.js +40 -28
- package/src/I18N.js +68 -0
- package/src/assign-modal.md +0 -4
- package/src/locale/ar-EG.js +5 -0
- package/src/locale/en-US.js +0 -0
- package/src/locale/es-ES.js +0 -0
- package/src/locale/ko-KR.js +0 -0
- package/src/locale/th-TH.js +0 -0
- package/src/locale/zh-CN.js +0 -0
- package/src/locale.js +0 -87
package/README.md
CHANGED
|
@@ -161,7 +161,7 @@ import { useEffect, useState, useCallback, useRef, useMemo } from 'react';
|
|
|
161
161
|
import { cloneDeep, debounce } from 'lodash';
|
|
162
162
|
import './index.less';
|
|
163
163
|
import { findSameCodePath, preorder, mergeAndDeduplicate, useWindowHeight } from './utils';
|
|
164
|
-
import { getText } from '../../
|
|
164
|
+
import { getText } from '../../I18N';
|
|
165
165
|
var path = []; // 上级机构到当前机构的路径
|
|
166
166
|
|
|
167
167
|
var AssignModal = function AssignModal(props) {
|
|
@@ -91,7 +91,7 @@ import { useEffect, useState, useCallback, useRef, useMemo } from 'react';
|
|
|
91
91
|
import { debounce } from 'lodash';
|
|
92
92
|
import './index.less';
|
|
93
93
|
import { findSameCodePath, preorder } from './utils';
|
|
94
|
-
import { getText } from '../../
|
|
94
|
+
import { getText } from '../../I18N';
|
|
95
95
|
var path = []; // 上级机构到当前机构的路径
|
|
96
96
|
|
|
97
97
|
var AssignModal = function AssignModal(props) {
|
package/es/AssignModal/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import _Drawer from 'tntd/es/drawer';
|
|
2
2
|
var _excluded = [
|
|
3
|
+
'I18N',
|
|
3
4
|
'visible',
|
|
4
5
|
'close',
|
|
5
6
|
'disabled',
|
|
6
7
|
'title',
|
|
7
8
|
'onSubmit',
|
|
8
|
-
'locale',
|
|
9
9
|
'okText',
|
|
10
10
|
'cancelText',
|
|
11
11
|
];
|
|
@@ -109,24 +109,37 @@ function _objectWithoutPropertiesLoose(r, e) {
|
|
|
109
109
|
return t;
|
|
110
110
|
}
|
|
111
111
|
import React from 'react';
|
|
112
|
+
import mapLocale, { getLang } from '../I18N';
|
|
112
113
|
import { useState } from 'react';
|
|
113
114
|
import AssignApp from './AssignApp';
|
|
114
115
|
import './index.less';
|
|
115
116
|
import Cookies from 'universal-cookie';
|
|
117
|
+
import LocaleReceiver from 'antd/es/locale-provider/LocaleReceiver';
|
|
116
118
|
var cookies = new Cookies();
|
|
117
119
|
var AssignModal = function AssignModal(props) {
|
|
118
|
-
var
|
|
120
|
+
var locale = props.locale;
|
|
121
|
+
var I18N = props.I18N,
|
|
122
|
+
visible = props.visible,
|
|
119
123
|
close = props.close,
|
|
120
124
|
_props$disabled = props.disabled,
|
|
121
125
|
disabled = _props$disabled === void 0 ? false : _props$disabled,
|
|
122
126
|
_props$title = props.title,
|
|
123
127
|
title = _props$title === void 0 ? '' : _props$title,
|
|
124
128
|
onSubmit = props.onSubmit,
|
|
125
|
-
locale = props.locale,
|
|
126
129
|
_props$okText = props.okText,
|
|
127
|
-
okText =
|
|
130
|
+
okText =
|
|
131
|
+
_props$okText === void 0
|
|
132
|
+
? locale === null || locale === void 0
|
|
133
|
+
? void 0
|
|
134
|
+
: locale.okText
|
|
135
|
+
: _props$okText,
|
|
128
136
|
_props$cancelText = props.cancelText,
|
|
129
|
-
cancelText =
|
|
137
|
+
cancelText =
|
|
138
|
+
_props$cancelText === void 0
|
|
139
|
+
? locale === null || locale === void 0
|
|
140
|
+
? void 0
|
|
141
|
+
: locale.cancelText
|
|
142
|
+
: _props$cancelText,
|
|
130
143
|
restProps = _objectWithoutProperties(props, _excluded);
|
|
131
144
|
var _useState = useState({}),
|
|
132
145
|
_useState2 = _slicedToArray(_useState, 2),
|
|
@@ -136,40 +149,51 @@ var AssignModal = function AssignModal(props) {
|
|
|
136
149
|
onSubmit(assignData);
|
|
137
150
|
};
|
|
138
151
|
return /*#__PURE__*/ React.createElement(
|
|
139
|
-
|
|
152
|
+
LocaleReceiver,
|
|
140
153
|
{
|
|
141
|
-
|
|
142
|
-
title: title,
|
|
143
|
-
visible: visible,
|
|
144
|
-
width: 900,
|
|
145
|
-
onCancel: close,
|
|
146
|
-
onOk: submit,
|
|
147
|
-
// okText={okText}
|
|
148
|
-
// cancelText={cancelText}
|
|
149
|
-
maskClosable: disabled,
|
|
150
|
-
destroyOnClose: true,
|
|
151
|
-
showFooter: !disabled,
|
|
152
|
-
okButtonProps: {
|
|
153
|
-
disabled: disabled,
|
|
154
|
-
},
|
|
154
|
+
componentName: 'AssignModal',
|
|
155
155
|
},
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
156
|
+
function (locale, localeCode) {
|
|
157
|
+
var I18N = !!Object.keys(locale).length
|
|
158
|
+
? locale
|
|
159
|
+
: mapLocale[localeCode] || mapLocale[getLang()];
|
|
160
|
+
return /*#__PURE__*/ React.createElement(
|
|
161
|
+
_Drawer,
|
|
159
162
|
{
|
|
160
|
-
|
|
161
|
-
|
|
163
|
+
className: 'modal-assign',
|
|
164
|
+
title: title,
|
|
165
|
+
visible: visible,
|
|
166
|
+
width: 900,
|
|
167
|
+
onCancel: close,
|
|
168
|
+
onOk: submit,
|
|
169
|
+
// okText={okText}
|
|
170
|
+
// cancelText={cancelText}
|
|
171
|
+
maskClosable: disabled,
|
|
172
|
+
destroyOnClose: true,
|
|
173
|
+
showFooter: !disabled,
|
|
174
|
+
okButtonProps: {
|
|
175
|
+
disabled: disabled,
|
|
162
176
|
},
|
|
163
|
-
disabled: disabled,
|
|
164
|
-
lang:
|
|
165
|
-
(props === null || props === void 0 ? void 0 : props.lang) ||
|
|
166
|
-
cookies.get('lang') ||
|
|
167
|
-
'cn',
|
|
168
|
-
locale: locale,
|
|
169
177
|
},
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
178
|
+
/*#__PURE__*/ React.createElement(
|
|
179
|
+
AssignApp,
|
|
180
|
+
_extends(
|
|
181
|
+
{
|
|
182
|
+
onChange: function onChange(data) {
|
|
183
|
+
setAssignData(data);
|
|
184
|
+
},
|
|
185
|
+
disabled: disabled,
|
|
186
|
+
lang:
|
|
187
|
+
(props === null || props === void 0 ? void 0 : props.lang) ||
|
|
188
|
+
cookies.get('lang') ||
|
|
189
|
+
'cn',
|
|
190
|
+
locale: I18N,
|
|
191
|
+
},
|
|
192
|
+
restProps,
|
|
193
|
+
),
|
|
194
|
+
),
|
|
195
|
+
);
|
|
196
|
+
},
|
|
173
197
|
);
|
|
174
198
|
};
|
|
175
199
|
export default AssignModal;
|
package/es/{locale.js → I18N.js}
RENAMED
|
@@ -18,50 +18,24 @@ function _typeof(o) {
|
|
|
18
18
|
);
|
|
19
19
|
}
|
|
20
20
|
import Cookies from 'universal-cookie';
|
|
21
|
+
import zhCN from './.octopus/zh-CN';
|
|
22
|
+
import enUS from './.octopus/en-US';
|
|
23
|
+
import thTH from './.octopus/th-TH';
|
|
24
|
+
import arEG from './.octopus/ar-EG';
|
|
25
|
+
import koKR from './.octopus/ko-KR';
|
|
26
|
+
import esES from './.octopus/es-ES';
|
|
21
27
|
var cookies = new Cookies();
|
|
22
|
-
export var zh_CN = {
|
|
23
|
-
authorizesOrgList: '机构列表',
|
|
24
|
-
allOrgAvailable: '全部机构',
|
|
25
|
-
authorizesAppList: '渠道列表',
|
|
26
|
-
allAppAvailable: '全部渠道',
|
|
27
|
-
authorizesUserList: '用户列表',
|
|
28
|
-
allUserAvailable: '全部用户',
|
|
29
|
-
search: '请输入机构名称',
|
|
30
|
-
availableOrgs: '可用机构',
|
|
31
|
-
availableApps: '可用渠道',
|
|
32
|
-
availableUsers: '可用用户',
|
|
33
|
-
clear: '清空',
|
|
34
|
-
hasBeenSelected: '已选',
|
|
35
|
-
numOfOrg: '%s 个机构',
|
|
36
|
-
numOfApp: '%s 个渠道',
|
|
37
|
-
numOfUser: '%s 个用户',
|
|
38
|
-
enterAppName: '请输入渠道名称',
|
|
39
|
-
enterUserName: '请输入用户名称',
|
|
40
|
-
};
|
|
41
|
-
export var en_US = {
|
|
42
|
-
authorizesOrgList: 'Organization List',
|
|
43
|
-
allOrgAvailable: 'All Organizations',
|
|
44
|
-
authorizesAppList: 'Channel List',
|
|
45
|
-
allAppAvailable: 'All Channels',
|
|
46
|
-
authorizesUserList: 'Account List',
|
|
47
|
-
allUserAvailable: 'All Accounts',
|
|
48
|
-
search: 'Organization name',
|
|
49
|
-
availableOrgs: 'Available Organizations',
|
|
50
|
-
availableApps: 'Available Channels',
|
|
51
|
-
availableUsers: 'Available Users',
|
|
52
|
-
clear: 'Clear',
|
|
53
|
-
hasBeenSelected: 'Selected',
|
|
54
|
-
numOfOrg: '%s Organizations',
|
|
55
|
-
numOfApp: '%s Channels',
|
|
56
|
-
numOfUser: '%s Accounts',
|
|
57
|
-
enterAppName: 'Enter Channel name',
|
|
58
|
-
enterUserName: 'Enter Account name',
|
|
59
|
-
};
|
|
60
28
|
|
|
61
|
-
//
|
|
29
|
+
// 语言包映射
|
|
62
30
|
var builtInLocales = {
|
|
63
|
-
cn:
|
|
64
|
-
|
|
31
|
+
'zh-cn': zhCN,
|
|
32
|
+
cn: zhCN,
|
|
33
|
+
// 兼容旧的 'cn' 标识
|
|
34
|
+
en: enUS,
|
|
35
|
+
th: thTH,
|
|
36
|
+
ar: arEG,
|
|
37
|
+
ko: koKR,
|
|
38
|
+
es: esES,
|
|
65
39
|
};
|
|
66
40
|
|
|
67
41
|
/**
|
|
@@ -90,8 +64,8 @@ export var getText = function getText(key, language, locale) {
|
|
|
90
64
|
actualLocale = null;
|
|
91
65
|
actualParams = locale !== undefined ? [locale].concat(params) : params;
|
|
92
66
|
}
|
|
93
|
-
var lang = language ||
|
|
94
|
-
var builtIn = builtInLocales[lang] ||
|
|
67
|
+
var lang = language || getLang();
|
|
68
|
+
var builtIn = builtInLocales[lang] || builtInLocales['zh-cn'];
|
|
95
69
|
|
|
96
70
|
// locale 是扁平对象(通过 createOtp 生成),直接覆盖内置语言包
|
|
97
71
|
var text =
|
|
@@ -112,14 +86,18 @@ export var getText = function getText(key, language, locale) {
|
|
|
112
86
|
}
|
|
113
87
|
return text;
|
|
114
88
|
};
|
|
115
|
-
export var
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
path: '/',
|
|
119
|
-
}) || 'cn'
|
|
120
|
-
);
|
|
89
|
+
export var getLang = function getLang() {
|
|
90
|
+
var lang = cookies.get('lang');
|
|
91
|
+
return lang !== 'cn' ? lang : 'zh-cn';
|
|
121
92
|
};
|
|
122
93
|
export default {
|
|
123
|
-
|
|
124
|
-
|
|
94
|
+
'zh-cn': zhCN,
|
|
95
|
+
en: enUS,
|
|
96
|
+
th: thTH,
|
|
97
|
+
// 泰语
|
|
98
|
+
ar: arEG,
|
|
99
|
+
// 阿拉伯语(埃及)
|
|
100
|
+
ko: koKR,
|
|
101
|
+
// 韩语
|
|
102
|
+
es: esES, // 西班牙语
|
|
125
103
|
};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tddc/assign-modal",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.4",
|
|
4
4
|
"description": "assign-modal",
|
|
5
5
|
"author": "zj <jun.zhang002383@tongdun.net>",
|
|
6
6
|
"license": "ISC",
|
|
@@ -18,4 +18,4 @@
|
|
|
18
18
|
"jsencrypt": "3.2.1"
|
|
19
19
|
},
|
|
20
20
|
"gitHead": "597697f3b6df285679feeabf56b25943a4ec89d4"
|
|
21
|
-
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
authorizesOrgList: 'Organization List',
|
|
3
|
+
allOrgAvailable: 'All Organizations',
|
|
4
|
+
authorizesAppList: 'Channel List',
|
|
5
|
+
allAppAvailable: 'All Channels',
|
|
6
|
+
authorizesUserList: 'Account List',
|
|
7
|
+
allUserAvailable: 'All Accounts',
|
|
8
|
+
search: 'Organization name',
|
|
9
|
+
availableOrgs: 'Available Organizations',
|
|
10
|
+
availableApps: 'Available Channels',
|
|
11
|
+
availableUsers: 'Available Users',
|
|
12
|
+
clear: 'Clear',
|
|
13
|
+
hasBeenSelected: 'Selected',
|
|
14
|
+
numOfOrg: '%s Organizations',
|
|
15
|
+
numOfApp: '%s Channels',
|
|
16
|
+
numOfUser: '%s Accounts',
|
|
17
|
+
enterAppName: 'Enter Channel name',
|
|
18
|
+
enterUserName: 'Enter Account name',
|
|
19
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
authorizesOrgList: '机构列表',
|
|
3
|
+
allOrgAvailable: '全部机构',
|
|
4
|
+
authorizesAppList: '渠道列表',
|
|
5
|
+
allAppAvailable: '全部渠道',
|
|
6
|
+
authorizesUserList: '用户列表',
|
|
7
|
+
allUserAvailable: '全部用户',
|
|
8
|
+
search: '请输入机构名称',
|
|
9
|
+
availableOrgs: '可用机构',
|
|
10
|
+
availableApps: '可用渠道',
|
|
11
|
+
availableUsers: '可用用户',
|
|
12
|
+
clear: '清空',
|
|
13
|
+
hasBeenSelected: '已选',
|
|
14
|
+
numOfOrg: '%s 个机构',
|
|
15
|
+
numOfApp: '%s 个渠道',
|
|
16
|
+
numOfUser: '%s 个用户',
|
|
17
|
+
enterAppName: '请输入渠道名称',
|
|
18
|
+
enterUserName: '请输入用户名称',
|
|
19
|
+
};
|
|
@@ -4,7 +4,7 @@ import { useEffect, useState, useCallback, useRef, useMemo } from 'react';
|
|
|
4
4
|
import { cloneDeep, debounce } from 'lodash';
|
|
5
5
|
import './index.less';
|
|
6
6
|
import { findSameCodePath, preorder, mergeAndDeduplicate, useWindowHeight } from './utils';
|
|
7
|
-
import { getText } from '../../
|
|
7
|
+
import { getText } from '../../I18N';
|
|
8
8
|
|
|
9
9
|
let path = []; // 上级机构到当前机构的路径
|
|
10
10
|
|
|
@@ -4,7 +4,7 @@ import { useEffect, useState, useCallback, useRef, useMemo } from 'react';
|
|
|
4
4
|
import { debounce } from 'lodash';
|
|
5
5
|
import './index.less';
|
|
6
6
|
import { findSameCodePath, preorder } from './utils';
|
|
7
|
-
import { getText } from '../../
|
|
7
|
+
import { getText } from '../../I18N';
|
|
8
8
|
|
|
9
9
|
let path = []; // 上级机构到当前机构的路径
|
|
10
10
|
|
package/src/AssignModal/index.js
CHANGED
|
@@ -1,21 +1,24 @@
|
|
|
1
|
+
import mapLocale, { getLang } from '../I18N';
|
|
1
2
|
import { Drawer } from 'tntd';
|
|
2
3
|
import { useState } from 'react';
|
|
3
|
-
|
|
4
4
|
import AssignApp from './AssignApp';
|
|
5
5
|
import './index.less';
|
|
6
6
|
import Cookies from 'universal-cookie';
|
|
7
|
+
import LocaleReceiver from 'antd/es/locale-provider/LocaleReceiver';
|
|
8
|
+
|
|
7
9
|
const cookies = new Cookies();
|
|
8
10
|
|
|
9
11
|
const AssignModal = (props) => {
|
|
12
|
+
const { locale } = props;
|
|
10
13
|
const {
|
|
14
|
+
I18N,
|
|
11
15
|
visible,
|
|
12
16
|
close,
|
|
13
17
|
disabled = false,
|
|
14
18
|
title = '',
|
|
15
19
|
onSubmit,
|
|
16
|
-
locale,
|
|
17
|
-
|
|
18
|
-
cancelText = '取消',
|
|
20
|
+
okText = locale?.okText,
|
|
21
|
+
cancelText = locale?.cancelText,
|
|
19
22
|
...restProps
|
|
20
23
|
} = props;
|
|
21
24
|
const [assignData, setAssignData] = useState({});
|
|
@@ -25,30 +28,39 @@ const AssignModal = (props) => {
|
|
|
25
28
|
};
|
|
26
29
|
|
|
27
30
|
return (
|
|
28
|
-
<
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
31
|
+
<LocaleReceiver componentName="AssignModal">
|
|
32
|
+
{(locale, localeCode) => {
|
|
33
|
+
const I18N = !!Object.keys(locale).length
|
|
34
|
+
? locale
|
|
35
|
+
: mapLocale[localeCode] || mapLocale[getLang()];
|
|
36
|
+
return (
|
|
37
|
+
<Drawer
|
|
38
|
+
className="modal-assign"
|
|
39
|
+
title={title}
|
|
40
|
+
visible={visible}
|
|
41
|
+
width={900}
|
|
42
|
+
onCancel={close}
|
|
43
|
+
onOk={submit}
|
|
44
|
+
// okText={okText}
|
|
45
|
+
// cancelText={cancelText}
|
|
46
|
+
maskClosable={disabled}
|
|
47
|
+
destroyOnClose
|
|
48
|
+
showFooter={!disabled}
|
|
49
|
+
okButtonProps={{ disabled }}
|
|
50
|
+
>
|
|
51
|
+
<AssignApp
|
|
52
|
+
onChange={(data) => {
|
|
53
|
+
setAssignData(data);
|
|
54
|
+
}}
|
|
55
|
+
disabled={disabled}
|
|
56
|
+
lang={props?.lang || cookies.get('lang') || 'cn'}
|
|
57
|
+
locale={I18N}
|
|
58
|
+
{...restProps}
|
|
59
|
+
/>
|
|
60
|
+
</Drawer>
|
|
61
|
+
);
|
|
62
|
+
}}
|
|
63
|
+
</LocaleReceiver>
|
|
52
64
|
);
|
|
53
65
|
};
|
|
54
66
|
|
package/src/I18N.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import Cookies from 'universal-cookie';
|
|
2
|
+
import zhCN from './.octopus/zh-CN';
|
|
3
|
+
import enUS from './.octopus/en-US';
|
|
4
|
+
import thTH from './.octopus/th-TH';
|
|
5
|
+
import arEG from './.octopus/ar-EG';
|
|
6
|
+
import koKR from './.octopus/ko-KR';
|
|
7
|
+
import esES from './.octopus/es-ES';
|
|
8
|
+
|
|
9
|
+
const cookies = new Cookies();
|
|
10
|
+
|
|
11
|
+
// 语言包映射
|
|
12
|
+
const builtInLocales = {
|
|
13
|
+
'zh-cn': zhCN,
|
|
14
|
+
cn: zhCN, // 兼容旧的 'cn' 标识
|
|
15
|
+
en: enUS,
|
|
16
|
+
th: thTH,
|
|
17
|
+
ar: arEG,
|
|
18
|
+
ko: koKR,
|
|
19
|
+
es: esES,
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* 获取文本,支持外部传入的语言包覆盖
|
|
24
|
+
* @param {string} key - 文本 key
|
|
25
|
+
* @param {string} language - 语言标识
|
|
26
|
+
* @param {Object} locale - 外部传入的语言包(可选),通过 createOtp 生成的扁平对象
|
|
27
|
+
* @param {...any} params - 替换参数
|
|
28
|
+
*/
|
|
29
|
+
export const getText = (key, language, locale, ...params) => {
|
|
30
|
+
// 兼容旧的调用方式:getText(key, language, ...params)
|
|
31
|
+
// 新的调用方式:getText(key, language, locale, ...params)
|
|
32
|
+
let actualLocale = locale;
|
|
33
|
+
let actualParams = params;
|
|
34
|
+
|
|
35
|
+
// 如果 locale 不是对象或为 null,则认为是旧的调用方式
|
|
36
|
+
if (typeof locale !== 'object' || locale === null) {
|
|
37
|
+
actualLocale = null;
|
|
38
|
+
actualParams = locale !== undefined ? [locale, ...params] : params;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const lang = language || getLang();
|
|
42
|
+
const builtIn = builtInLocales[lang] || builtInLocales['zh-cn'];
|
|
43
|
+
|
|
44
|
+
// locale 是扁平对象(通过 createOtp 生成),直接覆盖内置语言包
|
|
45
|
+
const text = actualLocale?.[key] ?? builtIn[key];
|
|
46
|
+
|
|
47
|
+
if (actualParams?.length) {
|
|
48
|
+
return actualParams.reduce((acc, cur) => {
|
|
49
|
+
return acc?.replace(/%s/, cur);
|
|
50
|
+
}, text);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return text;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export const getLang = () => {
|
|
57
|
+
const lang = cookies.get('lang');
|
|
58
|
+
return lang !== 'cn' ? lang : 'zh-cn';
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export default {
|
|
62
|
+
'zh-cn': zhCN,
|
|
63
|
+
en: enUS,
|
|
64
|
+
th: thTH, // 泰语
|
|
65
|
+
ar: arEG, // 阿拉伯语(埃及)
|
|
66
|
+
ko: koKR, // 韩语
|
|
67
|
+
es: esES, // 西班牙语
|
|
68
|
+
};
|
package/src/assign-modal.md
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/src/locale.js
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import Cookies from 'universal-cookie';
|
|
2
|
-
|
|
3
|
-
const cookies = new Cookies();
|
|
4
|
-
|
|
5
|
-
export const zh_CN = {
|
|
6
|
-
authorizesOrgList: '机构列表',
|
|
7
|
-
allOrgAvailable: '全部机构',
|
|
8
|
-
authorizesAppList: '渠道列表',
|
|
9
|
-
allAppAvailable: '全部渠道',
|
|
10
|
-
authorizesUserList: '用户列表',
|
|
11
|
-
allUserAvailable: '全部用户',
|
|
12
|
-
search: '请输入机构名称',
|
|
13
|
-
availableOrgs: '可用机构',
|
|
14
|
-
availableApps: '可用渠道',
|
|
15
|
-
availableUsers: '可用用户',
|
|
16
|
-
clear: '清空',
|
|
17
|
-
hasBeenSelected: '已选',
|
|
18
|
-
numOfOrg: '%s 个机构',
|
|
19
|
-
numOfApp: '%s 个渠道',
|
|
20
|
-
numOfUser: '%s 个用户',
|
|
21
|
-
enterAppName: '请输入渠道名称',
|
|
22
|
-
enterUserName: '请输入用户名称',
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export const en_US = {
|
|
26
|
-
authorizesOrgList: 'Organization List',
|
|
27
|
-
allOrgAvailable: 'All Organizations',
|
|
28
|
-
authorizesAppList: 'Channel List',
|
|
29
|
-
allAppAvailable: 'All Channels',
|
|
30
|
-
authorizesUserList: 'Account List',
|
|
31
|
-
allUserAvailable: 'All Accounts',
|
|
32
|
-
search: 'Organization name',
|
|
33
|
-
availableOrgs: 'Available Organizations',
|
|
34
|
-
availableApps: 'Available Channels',
|
|
35
|
-
availableUsers: 'Available Users',
|
|
36
|
-
clear: 'Clear',
|
|
37
|
-
hasBeenSelected: 'Selected',
|
|
38
|
-
numOfOrg: '%s Organizations',
|
|
39
|
-
numOfApp: '%s Channels',
|
|
40
|
-
numOfUser: '%s Accounts',
|
|
41
|
-
enterAppName: 'Enter Channel name',
|
|
42
|
-
enterUserName: 'Enter Account name',
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
// 内置语言包
|
|
46
|
-
const builtInLocales = {
|
|
47
|
-
cn: zh_CN,
|
|
48
|
-
en: en_US,
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* 获取文本,支持外部传入的语言包覆盖
|
|
53
|
-
* @param {string} key - 文本 key
|
|
54
|
-
* @param {string} language - 语言标识
|
|
55
|
-
* @param {Object} locale - 外部传入的语言包(可选),通过 createOtp 生成的扁平对象
|
|
56
|
-
* @param {...any} params - 替换参数
|
|
57
|
-
*/
|
|
58
|
-
export const getText = (key, language, locale, ...params) => {
|
|
59
|
-
// 兼容旧的调用方式:getText(key, language, ...params)
|
|
60
|
-
// 新的调用方式:getText(key, language, locale, ...params)
|
|
61
|
-
let actualLocale = locale;
|
|
62
|
-
let actualParams = params;
|
|
63
|
-
|
|
64
|
-
// 如果 locale 不是对象或为 null,则认为是旧的调用方式
|
|
65
|
-
if (typeof locale !== 'object' || locale === null) {
|
|
66
|
-
actualLocale = null;
|
|
67
|
-
actualParams = locale !== undefined ? [locale, ...params] : params;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const lang = language || getLanguage();
|
|
71
|
-
const builtIn = builtInLocales[lang] || zh_CN;
|
|
72
|
-
|
|
73
|
-
// locale 是扁平对象(通过 createOtp 生成),直接覆盖内置语言包
|
|
74
|
-
const text = actualLocale?.[key] ?? builtIn[key];
|
|
75
|
-
|
|
76
|
-
if (actualParams?.length) {
|
|
77
|
-
return actualParams.reduce((acc, cur) => {
|
|
78
|
-
return acc?.replace(/%s/, cur);
|
|
79
|
-
}, text);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
return text;
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
export const getLanguage = () => cookies.get('lang', { path: '/' }) || 'cn';
|
|
86
|
-
|
|
87
|
-
export default { en_US, zh_CN };
|