Файли
openidea/src/features/project-tree/filePath.ts
T
LU XIANGRUIтаwildcatDownstairs 87c4659547 fix(i18n): insert tx template values as written (#5177)
In the Chinese UI, Rename on a folder named `tasks` read 将目录“任务”及其用法重命名为:. The `tx` template tag translated every interpolated string that had a catalog entry of its own, so a file, branch, script or container name that matched a UI word (`tasks`, `Retry`) was shown translated. Values are now inserted as written. Call sites that interpolate the app's own UI words (kind labels, option titles, "Source"/"Target") mark them with the new `txPart(...)`, which is also translated again after a language change; the text catalog guard checks `txPart` literals too. `txTemplate` still translates captured parts.

Co-authored-by: wildcatDownstairs <[email protected]>
2026-11-22 15:14:54 +08:00

47 рядки
1.6 KiB
TypeScript
Неформатований Анотація Історія

Цей файл містить неоднозначні символи Юнікоду
Цей файл містить символи Юнікоду, які можна сплутати з іншими символами. Якщо ви вважаєте, що це зроблено навмисно, можете сміливо ігнорувати це попередження. Щоб показати їх, скористайтеся кнопкою Escape.
/** Navigate › File Path (⌥⌘F12): the file and its folders, each revealed in the OS file manager. */
import { openPopup } from "@/editor/lsp/popupStore";
import { canRevealInFileManager, fileManagerName, revealInFileManager } from "@/platform/fileManager";
import { notifications } from "@/workbench/contributions";
import { tx, txPart } from "@/platform/i18n";
import { nameOf, parentOf } from "./paths";
import { notifyRevealUnavailable } from "./operations";
const DRIVE_ROOT = /^[A-Za-z]:\/?$/;
/** `path` then each folder above it, up to the file system (or drive) root. */
export function filePathChain(path: string): string[] {
const out = [path];
for (let p = path; p !== "/" && !DRIVE_ROOT.test(p);) {
const parent = parentOf(p);
if (parent === p) break;
p = /^[A-Za-z]:$/.test(parent) ? `${parent}/` : parent;
out.push(p);
}
return out;
}
async function reveal(path: string) {
try {
await revealInFileManager(path);
} catch (e) {
const fileManager = txPart(fileManagerName());
notifications().notify({
level: "error",
title: tx`Cannot reveal in ${fileManager}`,
body: e instanceof Error ? e.message : String(e),
});
}
}
export function showFilePathPopup(path: string, isDir = false) {
if (!canRevealInFileManager()) return notifyRevealUnavailable();
const items = filePathChain(path).map((p, i) => ({
id: p,
label: nameOf(p) || p,
detail: i === 0 ? undefined : p,
icon: i === 0 && !isDir ? "file" : "folder",
run: () => reveal(p),
}));
openPopup({ kind: "list", anchor: { x: window.innerWidth / 2 - 160, y: 96 }, title: "File Path", items });
}