feat: add i18n supports for custom platform adapters#5045
Merged
Soulter merged 2 commits intoAstrBotDevs:masterfrom Feb 12, 2026
Merged
feat: add i18n supports for custom platform adapters#5045Soulter merged 2 commits intoAstrBotDevs:masterfrom
Soulter merged 2 commits intoAstrBotDevs:masterfrom
Conversation
Contributor
There was a problem hiding this comment.
Hey - 我发现了 1 个问题,并给出了一些整体性的反馈:
- 新增的
config.py中的_resolve_accept_language辅助函数目前没有被使用;请要么将其接入相关的请求/响应流程(例如在构造 i18n 负载时使用),要么移除它以避免产生死代码。 register_platform_adapter中的i18n_resources参数被标注为dict[str, str],但PlatformMetadata.i18n_resources的类型是dict[str, dict];请对齐这两处的类型,并明确预期的数据结构(例如{ 'zh-CN': { ... } }),以免让适配器作者产生困惑。
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The newly added `_resolve_accept_language` helper in `config.py` is currently unused; either wire it into the relevant request/response flow (e.g., when shaping i18n payloads) or remove it to avoid dead code.
- The `i18n_resources` parameter in `register_platform_adapter` is typed as `dict[str, str]`, but `PlatformMetadata.i18n_resources` is `dict[str, dict]`; aligning these types and clarifying the expected structure (e.g., `{ 'zh-CN': { ... } }`) will prevent confusion for adapter authors.
## Individual Comments
### Comment 1
<location> `astrbot/core/platform/register.py:18-19` </location>
<code_context>
adapter_display_name: str | None = None,
logo_path: str | None = None,
support_streaming_message: bool = True,
+ i18n_resources: dict[str, str] | None = None,
+ config_metadata: dict | None = None,
):
"""用于注册平台适配器的带参装饰器。
</code_context>
<issue_to_address>
**issue:** Align `i18n_resources` type annotation with `PlatformMetadata` to avoid confusion and misuse.
Here `i18n_resources` is annotated as `dict[str, str] | None`, while `PlatformMetadata.i18n_resources` is `dict[str, dict] | None`. This inconsistency suggests a different structure and can confuse users and type checkers. Please update the decorator parameter to match `PlatformMetadata` (likely `dict[str, dict] | None`).
</issue_to_address>帮我变得更有用!请对每条评论点 👍 或 👎,我会根据你的反馈改进后续的审查建议。
Original comment in English
Hey - I've found 1 issue, and left some high level feedback:
- The newly added
_resolve_accept_languagehelper inconfig.pyis currently unused; either wire it into the relevant request/response flow (e.g., when shaping i18n payloads) or remove it to avoid dead code. - The
i18n_resourcesparameter inregister_platform_adapteris typed asdict[str, str], butPlatformMetadata.i18n_resourcesisdict[str, dict]; aligning these types and clarifying the expected structure (e.g.,{ 'zh-CN': { ... } }) will prevent confusion for adapter authors.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The newly added `_resolve_accept_language` helper in `config.py` is currently unused; either wire it into the relevant request/response flow (e.g., when shaping i18n payloads) or remove it to avoid dead code.
- The `i18n_resources` parameter in `register_platform_adapter` is typed as `dict[str, str]`, but `PlatformMetadata.i18n_resources` is `dict[str, dict]`; aligning these types and clarifying the expected structure (e.g., `{ 'zh-CN': { ... } }`) will prevent confusion for adapter authors.
## Individual Comments
### Comment 1
<location> `astrbot/core/platform/register.py:18-19` </location>
<code_context>
adapter_display_name: str | None = None,
logo_path: str | None = None,
support_streaming_message: bool = True,
+ i18n_resources: dict[str, str] | None = None,
+ config_metadata: dict | None = None,
):
"""用于注册平台适配器的带参装饰器。
</code_context>
<issue_to_address>
**issue:** Align `i18n_resources` type annotation with `PlatformMetadata` to avoid confusion and misuse.
Here `i18n_resources` is annotated as `dict[str, str] | None`, while `PlatformMetadata.i18n_resources` is `dict[str, dict] | None`. This inconsistency suggests a different structure and can confuse users and type checkers. Please update the decorator parameter to match `PlatformMetadata` (likely `dict[str, dict] | None`).
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
b6e9b05 to
d4ea1b6
Compare
Member
|
你好,请问可以给一个修改之后的 的例子嘛 |
Contributor
Author
|
1 task
Soulter
approved these changes
Feb 12, 2026
Added references to pull request 5045 in docstrings.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
目前,由插件提供的适配器通过 monkey patch 的方法注入 metadata ,然而,此举在最近版本的 UI 中遭到了损坏,此修改旨在为其提供可用的修饰器参数
Modifications / 改动点
astrbot/core/platform/platform_metadata.py
添加了可选的metadata和i18n传入
astrbot/dashboard/routes/config.py
为外部平台添加了专门的 platform_i18n_translations 键值
dashboard/src/components/platform/AddNewPlatform.vue
添加了平台图标回落(对于外部注入的部分)
dashboard/src/i18n/composables.ts
dashboard/src/main.ts
dashboard/src/views/ConfigPage.vue
dashboard/src/views/ExtensionPage.vue
dashboard/src/views/PlatformPage.vue
添加动态多语言
Screenshots or Test Results / 运行截图或测试结果
Checklist / 检查清单
requirements.txt和pyproject.toml文件相应位置。/ I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations inrequirements.txtandpyproject.toml.由 Sourcery 提供的总结
为插件提供的平台适配器新增一等公民的元数据和国际化(i18n)支持,使其配置界面和文本可以按不同语言环境(locale)动态渲染。
新功能:
缺陷修复:
改进增强:
Original summary in English
Summary by Sourcery
Add first-class metadata and i18n support for plugin-provided platform adapters so their configuration UIs and texts can be dynamically rendered per locale.
New Features:
Bug Fixes:
Enhancements: