feat:为webui配置名提供中文翻译,并修改优化布局

This commit is contained in:
SengokuCola
2026-05-06 15:45:50 +08:00
parent b3d16a5705
commit 8c73424583
24 changed files with 538 additions and 132 deletions

View File

@@ -36,6 +36,11 @@ class BotConfig(ConfigBase):
platform: str = Field(
default="",
json_schema_extra={
"label": {
"zh_CN": "平台",
"en_US": "Platform",
"ja_JP": "プラットフォーム",
},
"x-widget": "input",
"x-icon": "wifi",
"x-layout": "inline-right",
@@ -48,6 +53,11 @@ class BotConfig(ConfigBase):
qq_account: str = Field(
default="",
json_schema_extra={
"label": {
"zh_CN": "QQ账号",
"en_US": "QQ account",
"ja_JP": "QQアカウント",
},
"x-widget": "input",
"x-icon": "user",
"x-layout": "inline-right",
@@ -69,6 +79,11 @@ class BotConfig(ConfigBase):
nickname: str = Field(
default="麦麦",
json_schema_extra={
"label": {
"zh_CN": "机器人昵称",
"en_US": "Bot nickname",
"ja_JP": "ボットのニックネーム",
},
"x-widget": "input",
"x-icon": "user-circle",
},
@@ -333,6 +348,11 @@ class ChatConfig(ConfigBase):
chat_prompts: list["ExtraPromptItem"] = Field(
default_factory=lambda: [],
json_schema_extra={
"label": {
"zh_CN": "额外 Prompt",
"en_US": "Extra prompts",
"ja_JP": "追加プロンプト",
},
"x-widget": "custom",
"x-icon": "list",
},
@@ -341,6 +361,11 @@ class ChatConfig(ConfigBase):
enable_talk_value_rules: bool = Field(
default=True,
json_schema_extra={
"label": {
"zh_CN": "启用动态发言频率规则",
"en_US": "Enable dynamic talk frequency rules",
"ja_JP": "動的な発言頻度ルールを有効化",
},
"x-widget": "switch",
"x-icon": "settings",
},
@@ -353,6 +378,11 @@ class ChatConfig(ConfigBase):
TalkRulesItem(platform="", item_id="", rule_type="group", time="09:00-18:59", value=1.0),
],
json_schema_extra={
"label": {
"zh_CN": "动态发言频率规则",
"en_US": "Dynamic talk frequency rules",
"ja_JP": "動的な発言頻度ルール",
},
"x-widget": "custom",
"x-icon": "list",
},

View File

@@ -1,12 +1,17 @@
import inspect
from typing import Any, Dict, List, get_args, get_origin
from pydantic_core import PydanticUndefined
import inspect
from src.config.config_base import ConfigBase
class ConfigSchemaGenerator:
@staticmethod
def _build_label(label: str) -> Dict[str, str]:
return {"zh_CN": label}
@classmethod
def generate_schema(cls, config_class: type[ConfigBase], include_nested: bool = True) -> Dict[str, Any]:
return cls.generate_config_schema(config_class, include_nested=include_nested)
@@ -76,7 +81,7 @@ class ConfigSchemaGenerator:
schema: Dict[str, Any] = {
"name": field_name,
"type": field_type,
"label": field_name,
"label": cls._build_label(field_name),
"description": description,
"required": field_info.is_required(),
}