mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 17:38:19 +08:00
ui: speed up page load
This commit is contained in:
15 files changed
+80
-106
No files matched your search
@@ -1,11 +1,7 @@
|
||||
/* eslint-disable camelcase */
|
||||
import en_GB from 'monaco-editor-nls/locale/en-gb.json';
|
||||
|
||||
function format(message, args) {
|
||||
let result;
|
||||
if (args.length === 0) {
|
||||
result = message;
|
||||
} else {
|
||||
if (!args.length) result = message;
|
||||
else {
|
||||
result = String(message).replace(/\{(\d+)\}/g, (match, rest) => {
|
||||
const index = rest[0];
|
||||
return typeof args[index] !== 'undefined' ? args[index] : match;
|
||||
@@ -18,28 +14,12 @@ export const getConfiguredDefaultLocale = () => 'zh';
|
||||
|
||||
let CURRENT_LOCALE_DATA = {}; // eslint-disable-line @typescript-eslint/naming-convention
|
||||
|
||||
function find(path, message) {
|
||||
for (const key of Object.keys(CURRENT_LOCALE_DATA)) {
|
||||
if (!CURRENT_LOCALE_DATA[key] || !en_GB[key]) continue;
|
||||
if (CURRENT_LOCALE_DATA[key][path] && en_GB[key][path] === message) {
|
||||
return CURRENT_LOCALE_DATA[key][path];
|
||||
}
|
||||
}
|
||||
for (const key of Object.keys(CURRENT_LOCALE_DATA)) {
|
||||
if (!CURRENT_LOCALE_DATA[key]) continue;
|
||||
if (CURRENT_LOCALE_DATA[key][path]) {
|
||||
return CURRENT_LOCALE_DATA[key][path];
|
||||
}
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
export function localize(path, message, ...args) {
|
||||
return format(find(path.key || path, message), args);
|
||||
return format(CURRENT_LOCALE_DATA[path.key || path] || message, args);
|
||||
}
|
||||
|
||||
export function setLocaleData(data) {
|
||||
CURRENT_LOCALE_DATA = data;
|
||||
CURRENT_LOCALE_DATA = Object.assign(...Object.values(data));
|
||||
}
|
||||
|
||||
export function loadMessageBundle() {
|
||||
|
||||
Reference in new issue
Block a user