plain-design 1.0.0-beta.57 → 1.0.0-beta.59
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/package.json
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
import {createSyncHooks, reactive} from "plain-design-composition";
|
2
2
|
import {ZhCnLocale} from './lang/zh-cn';
|
3
3
|
import {deepmerge} from "../components/PageThemeUtils/deepmerge";
|
4
|
+
import {PlainObject} from "plain-utils/utils/event";
|
4
5
|
|
5
6
|
/**
|
6
7
|
/**
|
@@ -159,19 +160,53 @@ export const i18n = (() => {
|
|
159
160
|
*/
|
160
161
|
const setLangs = (langs: any) => {
|
161
162
|
|
162
|
-
let
|
163
|
+
let result = {} as any;
|
163
164
|
Object.keys({ ...state.langs, ...langs }).forEach(localeName => {
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
165
|
+
result[localeName] = mergeLangs(
|
166
|
+
state.langs[localeName],
|
167
|
+
langs[localeName],
|
168
|
+
(lang1, lang2) => {
|
169
|
+
return mergeLangs(
|
170
|
+
lang1,
|
171
|
+
lang2,
|
172
|
+
(item1, item2) => {
|
173
|
+
return {
|
174
|
+
...item1,
|
175
|
+
...item2,
|
176
|
+
};
|
177
|
+
}
|
178
|
+
);
|
179
|
+
}
|
180
|
+
);
|
168
181
|
});
|
169
182
|
|
170
|
-
state.langs =
|
183
|
+
state.langs = result;
|
171
184
|
|
172
185
|
hooks.onUpdateLangs.exec(undefined);
|
173
186
|
};
|
174
187
|
|
188
|
+
const mergeLangs = (lang1: PlainObject | undefined, lang2: PlainObject | undefined, merge: (val1: PlainObject, val2: PlainObject) => PlainObject | undefined): PlainObject | undefined => {
|
189
|
+
|
190
|
+
if (!lang1 || !lang2) {
|
191
|
+
return lang1 || lang2;
|
192
|
+
}
|
193
|
+
|
194
|
+
const keys = new Set<string>();
|
195
|
+
Object.keys(lang1).forEach(key => {keys.add(key);});
|
196
|
+
Object.keys(lang2).forEach(key => {keys.add(key);});
|
197
|
+
const result = {} as PlainObject;
|
198
|
+
keys.forEach((key) => {
|
199
|
+
const val1 = lang1[key];
|
200
|
+
const val2 = lang2[key];
|
201
|
+
if (!!val1 && !!val2) {
|
202
|
+
result[key] = merge(val1, val2);
|
203
|
+
} else {
|
204
|
+
result[key] = val1 || val2;
|
205
|
+
}
|
206
|
+
});
|
207
|
+
return result;
|
208
|
+
};
|
209
|
+
|
175
210
|
return {
|
176
211
|
$t,
|
177
212
|
$intl,
|