diff --git a/astrbot/core/config/i18n_utils.py b/astrbot/core/config/i18n_utils.py index aa441c0c16..cb6b6429b5 100644 --- a/astrbot/core/config/i18n_utils.py +++ b/astrbot/core/config/i18n_utils.py @@ -42,6 +42,55 @@ def convert_to_i18n_keys(metadata: dict[str, Any]) -> dict[str, Any]: """ result = {} + def convert_items( + group: str, section: str, items: dict[str, Any], prefix: str = "" + ) -> dict[str, Any]: + items_result: dict[str, Any] = {} + + for field_key, field_data in items.items(): + if not isinstance(field_data, dict): + items_result[field_key] = field_data + continue + + field_name = field_key + field_path = f"{prefix}.{field_name}" if prefix else field_name + + field_result = { + key: value + for key, value in field_data.items() + if key not in {"description", "hint", "labels", "name"} + } + + if "description" in field_data: + field_result["description"] = ( + f"{group}.{section}.{field_path}.description" + ) + if "hint" in field_data: + field_result["hint"] = f"{group}.{section}.{field_path}.hint" + if "labels" in field_data: + field_result["labels"] = f"{group}.{section}.{field_path}.labels" + if "name" in field_data: + field_result["name"] = f"{group}.{section}.{field_path}.name" + + if "items" in field_data and isinstance(field_data["items"], dict): + field_result["items"] = convert_items( + group, section, field_data["items"], field_path + ) + + if "template_schema" in field_data and isinstance( + field_data["template_schema"], dict + ): + field_result["template_schema"] = convert_items( + group, + section, + field_data["template_schema"], + f"{field_path}.template_schema", + ) + + items_result[field_key] = field_result + + return items_result + for group_key, group_data in metadata.items(): group_result = { "name": f"{group_key}.name", @@ -50,59 +99,19 @@ def convert_to_i18n_keys(metadata: dict[str, Any]) -> dict[str, Any]: for section_key, section_data in group_data.get("metadata", {}).items(): section_result = { - "description": f"{group_key}.{section_key}.description", - "type": section_data.get("type"), + key: value + for key, value in section_data.items() + if key not in {"description", "hint", "labels", "name"} } + section_result["description"] = f"{group_key}.{section_key}.description" - # 复制其他属性 - for key in ["items", "condition", "_special", "invisible"]: - if key in section_data: - section_result[key] = section_data[key] - - # 处理 hint if "hint" in section_data: section_result["hint"] = f"{group_key}.{section_key}.hint" - # 处理 items 中的字段 if "items" in section_data and isinstance(section_data["items"], dict): - items_result = {} - for field_key, field_data in section_data["items"].items(): - # 处理嵌套的点号字段名(如 provider_settings.enable) - field_name = field_key - - field_result = {} - - # 复制基本属性 - for attr in [ - "type", - "condition", - "_special", - "invisible", - "options", - "slider", - ]: - if attr in field_data: - field_result[attr] = field_data[attr] - - # 转换文本属性为国际化键 - if "description" in field_data: - field_result["description"] = ( - f"{group_key}.{section_key}.{field_name}.description" - ) - - if "hint" in field_data: - field_result["hint"] = ( - f"{group_key}.{section_key}.{field_name}.hint" - ) - - if "labels" in field_data: - field_result["labels"] = ( - f"{group_key}.{section_key}.{field_name}.labels" - ) - - items_result[field_key] = field_result - - section_result["items"] = items_result + section_result["items"] = convert_items( + group_key, section_key, section_data["items"] + ) group_result["metadata"][section_key] = section_result diff --git a/astrbot/dashboard/routes/config.py b/astrbot/dashboard/routes/config.py index c5998682c8..e018d64755 100644 --- a/astrbot/dashboard/routes/config.py +++ b/astrbot/dashboard/routes/config.py @@ -1,4 +1,5 @@ import asyncio +import copy import inspect import os import traceback @@ -407,8 +408,19 @@ async def update_provider_source(self): return Response().ok(message="更新 provider source 成功").__dict__ async def get_provider_template(self): + provider_metadata = ConfigMetadataI18n.convert_to_i18n_keys( + { + "provider_group": { + "metadata": { + "provider": CONFIG_METADATA_2["provider_group"]["metadata"][ + "provider" + ] + } + } + } + ) config_schema = { - "provider": CONFIG_METADATA_2["provider_group"]["metadata"]["provider"] + "provider": provider_metadata["provider_group"]["metadata"]["provider"] } data = { "config_schema": config_schema, @@ -1278,11 +1290,24 @@ async def _register_platform_logo(self, platform, platform_default_tmpl): async def _get_astrbot_config(self): config = self.config + metadata = copy.deepcopy(CONFIG_METADATA_2) + platform_i18n = ConfigMetadataI18n.convert_to_i18n_keys( + { + "platform_group": { + "metadata": { + "platform": metadata["platform_group"]["metadata"]["platform"] + } + } + } + ) + metadata["platform_group"]["metadata"]["platform"] = platform_i18n[ + "platform_group" + ]["metadata"]["platform"] # 平台适配器的默认配置模板注入 - platform_default_tmpl = CONFIG_METADATA_2["platform_group"]["metadata"][ - "platform" - ]["config_template"] + platform_default_tmpl = metadata["platform_group"]["metadata"]["platform"][ + "config_template" + ] # 收集需要注册logo的平台 logo_registration_tasks = [] @@ -1300,14 +1325,14 @@ async def _get_astrbot_config(self): await asyncio.gather(*logo_registration_tasks, return_exceptions=True) # 服务提供商的默认配置模板注入 - provider_default_tmpl = CONFIG_METADATA_2["provider_group"]["metadata"][ - "provider" - ]["config_template"] + provider_default_tmpl = metadata["provider_group"]["metadata"]["provider"][ + "config_template" + ] for provider in provider_registry: if provider.default_config_tmpl: provider_default_tmpl[provider.type] = provider.default_config_tmpl - return {"metadata": CONFIG_METADATA_2, "config": config} + return {"metadata": metadata, "config": config} async def _get_plugin_config(self, plugin_name: str): ret: dict = {"metadata": None, "config": None} diff --git a/dashboard/src/components/platform/AddNewPlatform.vue b/dashboard/src/components/platform/AddNewPlatform.vue index 118aa202a8..3be4d92f60 100644 --- a/dashboard/src/components/platform/AddNewPlatform.vue +++ b/dashboard/src/components/platform/AddNewPlatform.vue @@ -9,14 +9,14 @@
无法加载默认配置模板
+{{ tm('createDialog.newConfigLoadFailed') }}