дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-04 01:01:17 +02:00
fix(plugins): translate the command title in a failed plugin command's notification (#7874)
A failed plugin command's notification used the command's declared English title even when the plugin ships a translation that the menus and command palette already show. commandTitle now passes the title through that plugin's catalog. Co-authored-by: audichuang <[email protected]>
Цей коміт міститься в:
1 джерело
7eed207163
коміт
ac9198dd52
2 files changed
+30
-2
No files matched your search
@@ -0,0 +1,26 @@
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
import { usePluginCatalogs } from "./pluginText";
|
||||
import { commandTitle, usePlugins } from "./store";
|
||||
|
||||
describe("commandTitle", () => {
|
||||
afterEach(() => {
|
||||
usePlugins.setState({ ui: [] });
|
||||
usePluginCatalogs.setState({ catalogs: {} });
|
||||
});
|
||||
|
||||
it("uses the plugin's translation of the command title", () => {
|
||||
usePlugins.setState({
|
||||
ui: [{ pluginId: "a", point: "commands", key: "show", decl: { id: "show", title: "Note: Show" } }],
|
||||
});
|
||||
usePluginCatalogs.setState({ catalogs: { a: { "Note: Show": "筆記:顯示" }, b: { "Note: Show": "x" } } });
|
||||
expect(commandTitle("a", "show")).toBe("筆記:顯示");
|
||||
});
|
||||
|
||||
it("keeps the declared title without a translation and the id without a title", () => {
|
||||
usePlugins.setState({
|
||||
ui: [{ pluginId: "a", point: "commands", key: "show", decl: { id: "show", title: "Note: Show" } }],
|
||||
});
|
||||
expect(commandTitle("a", "show")).toBe("Note: Show");
|
||||
expect(commandTitle("a", "missing")).toBe("missing");
|
||||
});
|
||||
});
|
||||
@@ -16,6 +16,7 @@ import { notifications } from "@/workbench/contributions";
|
||||
import { pluginsBackend, type PluginsBackend } from "./backend";
|
||||
import { editorContext } from "./editorContext";
|
||||
import { iconThemeKey, selectedIconTheme, selectIconTheme } from "./iconThemes";
|
||||
import { translatorOf, usePluginCatalogs } from "./pluginText";
|
||||
|
||||
export const SETTINGS_PAGE_ID = "plugins";
|
||||
/** `plugins#permissions:<id>`: the Plugins page selects that plugin with its permissions in view. */
|
||||
@@ -447,13 +448,14 @@ export async function selectPluginTheme(pluginId: string | null, themeId: string
|
||||
}
|
||||
}
|
||||
|
||||
/** Title of a plugin command from its UI contribution. */
|
||||
/** Title of a plugin command from its UI contribution, in the plugin's translation for the UI language. */
|
||||
export function commandTitle(pluginId: string, commandId: string): string {
|
||||
const item = usePlugins
|
||||
.getState()
|
||||
.ui.find((c) => c.point === "commands" && c.pluginId === pluginId && c.key === commandId);
|
||||
const title = (item?.decl as { title?: unknown } | undefined)?.title;
|
||||
return typeof title === "string" ? title : commandId;
|
||||
if (typeof title !== "string") return commandId;
|
||||
return translatorOf(usePluginCatalogs.getState().catalogs, pluginId)(title);
|
||||
}
|
||||
|
||||
/** Runs a plugin command from an action; failures become notifications. */
|
||||
|
||||
Reference in new issue
Заблокувати користувача