Skip to content

Commit 1f1d3fb

Browse files
wcqqq1214Soulter
andauthored
fix(dashboard): localize plugin names in sidebar (#10576)
* fix(dashboard): localize plugin names in sidebar * test: simplify plugin sidebar i18n regression coverage * Delete dashboard/tests/pluginSidebarItems.test.mjs --------- Co-authored-by: Soulter <37870767+Soulter@users.noreply.github.com>
1 parent f4a345a commit 1f1d3fb

3 files changed

Lines changed: 22 additions & 2 deletions

File tree

‎dashboard/src/composables/usePluginSidebarItems.ts‎

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { reactive, shallowRef, onMounted, watch } from "vue";
22
import { pluginApi } from "@/api/v1";
33
import { useI18n } from "@/i18n/composables";
4+
import { resolvePluginI18n } from "@/utils/pluginI18n";
45
import type { menu } from "@/layouts/full/vertical-sidebar/sidebarItem";
56

67
const DEFAULT_ICON = "mdi-puzzle";
@@ -17,6 +18,7 @@ interface PluginEntry {
1718
i18n?: Record<
1819
string,
1920
{
21+
metadata?: { display_name?: unknown };
2022
views?: Record<string, { title?: unknown }>;
2123
pages?: Record<string, { title?: unknown }>;
2224
}
@@ -54,7 +56,14 @@ function buildPageItem(
5456
locale: string,
5557
grouped: boolean,
5658
): menu {
57-
const displayName = p.display_name || p.name || "Unknown Plugin";
59+
const displayName =
60+
[
61+
resolvePluginI18n(p.i18n, locale, "metadata.display_name"),
62+
p.display_name,
63+
p.name,
64+
]
65+
.find((value) => typeof value === "string" && value.trim())
66+
?.trim() || "Unknown Plugin";
5867
const localeData = p.i18n?.[locale];
5968
const localizedTitle =
6069
localeData && typeof localeData === "object"
@@ -83,7 +92,14 @@ function buildPluginGroups(plugins: PluginEntry[], locale: string): menu[] {
8392
return plugins
8493
.filter((p) => p.activated && Array.isArray(p.pages) && p.pages.length > 0)
8594
.map((p) => {
86-
const displayName = p.display_name || p.name || "Unknown Plugin";
95+
const displayName =
96+
[
97+
resolvePluginI18n(p.i18n, locale, "metadata.display_name"),
98+
p.display_name,
99+
p.name,
100+
]
101+
.find((value) => typeof value === "string" && value.trim())
102+
?.trim() || "Unknown Plugin";
87103
return {
88104
value: `plugin:${p.name}`,
89105
title: displayName,

‎docs/en/dev/star/guides/plugin-i18n.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ When the current locale has no translation, a field is missing, or the locale fi
2626

2727
`metadata` overrides the plugin name, card short description, and description shown on plugin pages.
2828

29+
Sidebar plugin group headings, hover cards, and default titles that use the plugin name also read `metadata.display_name` for the current locale and update immediately when the language changes. The sidebar accepts only nonempty strings; missing, blank, or invalid translations fall back to the original `display_name`, then `name`. The existing precedence of `views.<view>.title` over `pages.<view>.title` stays unchanged; grouped views without a valid title still show their directory name. Routes, pinned items, and expanded groups use stable plugin IDs or view paths and do not change with translated names.
30+
2931
```json
3032
{
3133
"metadata": {

‎docs/zh/dev/star/guides/plugin-i18n.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ your_plugin/
2626

2727
`metadata` 用于覆盖插件在插件页展示的名称、卡片短描述和描述。
2828

29+
侧栏的插件分组标题、悬浮提示和使用插件名称的默认标题也会读取当前语言的 `metadata.display_name`,切换语言后立即更新。侧栏只接受非空字符串;翻译缺失、为空白或类型无效时,依次回退到原始 `display_name`、`name`。已有 `views.<视图名>.title` 优先于 `pages.<视图名>.title` 的解析规则不变;分组内没有有效标题的视图仍显示目录名。路由、置顶和展开状态使用稳定的插件 ID 或视图路径,不随名称翻译变化。
30+
2931
```json
3032
{
3133
"metadata": {

0 commit comments

Comments
 (0)