mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
feats::
统一语言配置位置 支持langs继承 支持归类
This commit is contained in:
1 parent
5902b4d4b6
commit
377ef55d49
27 files changed
+253
-658
No files matched your search
@@ -519,23 +519,6 @@ export const CATEGORIES = {
|
||||
],
|
||||
};
|
||||
|
||||
export const LANG_TEXTS = {
|
||||
c: 'C',
|
||||
cc: 'C++',
|
||||
cs: 'C#',
|
||||
pas: 'Pascal',
|
||||
java: 'Java',
|
||||
py: 'Python',
|
||||
py3: 'Python 3',
|
||||
php: 'PHP',
|
||||
rs: 'Rust',
|
||||
hs: 'Haskell',
|
||||
js: 'JavaScript',
|
||||
go: 'Go',
|
||||
rb: 'Ruby',
|
||||
jl: 'Julia',
|
||||
};
|
||||
|
||||
global.Hydro.model.builtin = {
|
||||
Permission,
|
||||
PERM,
|
||||
@@ -547,7 +530,6 @@ global.Hydro.model.builtin = {
|
||||
BUILTIN_ROLES,
|
||||
DEFAULT_NODES,
|
||||
CATEGORIES,
|
||||
LANG_TEXTS,
|
||||
STATUS,
|
||||
STATUS_TEXTS,
|
||||
STATUS_CODES,
|
||||
|
||||
@@ -3,6 +3,7 @@ import moment from 'moment-timezone';
|
||||
import { Dictionary } from 'lodash';
|
||||
import yaml from 'js-yaml';
|
||||
import { retry } from '@hydrooj/utils/lib/utils';
|
||||
import { parseLang } from '@hydrooj/utils/lib/lang';
|
||||
import * as builtin from './builtin';
|
||||
import { Setting as _Setting } from '../interface';
|
||||
import { Logger } from '../logger';
|
||||
@@ -98,10 +99,30 @@ export const SystemSetting = (...settings: _Setting[]) => {
|
||||
}
|
||||
};
|
||||
|
||||
const LangSettingNode = {
|
||||
family: 'setting_usage',
|
||||
key: 'codeLang',
|
||||
value: 'c',
|
||||
name: 'codeLang',
|
||||
desc: 'Default Code Language',
|
||||
flag: 0,
|
||||
subType: '',
|
||||
type: 'select',
|
||||
range: {},
|
||||
};
|
||||
|
||||
bus.on('system/setting', (args) => {
|
||||
if (!args['hydrooj.lang']) return;
|
||||
const lang = parseLang(args['hydrooj.lang']);
|
||||
const range = {};
|
||||
for (const key in lang) range[key] = lang[key].display;
|
||||
LangSettingNode.range = range;
|
||||
});
|
||||
|
||||
PreferenceSetting(
|
||||
Setting('setting_display', 'viewLang', null, langRange, 'UI Language'),
|
||||
Setting('setting_display', 'timeZone', 'Asia/Shanghai', timezones, 'Timezone'),
|
||||
Setting('setting_usage', 'codeLang', 'c', builtin.LANG_TEXTS, 'Default Code Language'),
|
||||
LangSettingNode,
|
||||
Setting('setting_usage', 'codeTemplate', '', 'textarea', 'Default Code Template',
|
||||
'If left blank, the built-in template of the corresponding language will be used.'),
|
||||
);
|
||||
@@ -165,7 +186,6 @@ SystemSetting(
|
||||
Setting('setting_limits', 'limit.problem_files_max', 100, 'number', 'limit.problem_files_max', 'Max files per problem'),
|
||||
Setting('setting_basic', 'default.priv', builtin.PRIV.PRIV_DEFAULT, 'number', 'default.priv', 'Default Privilege'),
|
||||
Setting('setting_basic', 'problem.categories', builtin.CATEGORIES, 'yaml', 'problem.categories', 'Problem Categories'),
|
||||
Setting('setting_basic', 'lang.texts', builtin.LANG_TEXTS, 'yaml', 'lang.texts', 'LANG_TEXTS'),
|
||||
Setting('setting_basic', 'pagination.problem', 100, 'number', 'pagination.problem', 'Problems per page'),
|
||||
Setting('setting_basic', 'pagination.contest', 20, 'number', 'pagination.contest', 'Contests per page'),
|
||||
Setting('setting_basic', 'pagination.discussion', 50, 'number', 'pagination.discussion', 'Discussions per page'),
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { parseLang } from '@hydrooj/utils/lib/lang';
|
||||
import { SYSTEM_SETTINGS } from './setting';
|
||||
import { NumberKeys } from '../typeutils';
|
||||
import { SystemKeys } from '../interface';
|
||||
@@ -70,8 +71,13 @@ export async function runConfig() {
|
||||
await bus.emit('database/config');
|
||||
}
|
||||
|
||||
// eslint-disable-next-line import/no-mutable-exports
|
||||
export let lang = {};
|
||||
|
||||
bus.on('system/setting', (args) => {
|
||||
for (const key in args) set(key, args[key], false);
|
||||
if (!args['hydrooj.lang']) return;
|
||||
lang = parseLang(args['hydrooj.lang']);
|
||||
});
|
||||
|
||||
global.Hydro.model.system = {
|
||||
@@ -80,4 +86,5 @@ global.Hydro.model.system = {
|
||||
getMany,
|
||||
inc,
|
||||
set,
|
||||
lang,
|
||||
};
|
||||
Reference in new issue
Block a user