The IDE you know, rebuilt in Rust. IntelliJ IDEA–style keymap, tool windows and search-everywhere in a fast native app: editor, code insight, debugger, Git, terminal, database and HTTP clients for 60+ languages.
TypeScript code-editorcross-platformdapdatabase-clientdebuggerdesktop-appdeveloper-toolsgithttp-clientideintellijlsprusttauriterminal
fix(i18n): translate counts inside the Update Project and Hot Swap results (#994)
l0ng-ai59766278c521
diff --git a/src/features/debugger/__tests__/hotswap.test.ts b/src/features/debugger/__tests__/hotswap.test.tsindex ace2fc1b3..3473a32b1 100644--- a/src/features/debugger/__tests__/hotswap.test.ts+++ b/src/features/debugger/__tests__/hotswap.test.ts@@ -29,6 +29,7 @@ vi.mock("@/workbench/contributions", async (importOriginal) => {import type { DebugCapabilities, DebugSessionId } from "@/platform/ipc";import { getContext } from "@/platform/context";+import { _resetI18nForTests, setLocale } from "@/platform/i18n";import { hotSwapMessage, onHotCodeReplace, reloadChangedClasses } from "../hotswap";import { publishContext, useDebug, type DebugSession } from "../state";@@ -107,9 +108,19 @@ describe("HotSwap", () => {it("words results like IDEA", () => {expect(hotSwapMessage(0, []).title).toBe("Loaded classes are up to date. Nothing to reload.");expect(hotSwapMessage(1, []).title).toBe("1 class reloaded");+ expect(hotSwapMessage(3, []).title).toBe("3 classes reloaded");expect(hotSwapMessage(3, ["boom"])).toMatchObject({ level: "error", body: "boom" });});+ it("translates the reload count with the sentence", async () => {+ await setLocale("zh");+ try {+ expect(hotSwapMessage(3, []).title).toBe("已重新加载 3 个类");+ } finally {+ _resetI18nForTests();+ }+ });+it("offers a reload when java-debug reports a finished build", () => {// Past the quiet period after the reloads above (their own builds raise no prompt).vi.spyOn(Date, "now").mockReturnValue(Date.now() + 120_000);diff --git a/src/features/debugger/hotswap.ts b/src/features/debugger/hotswap.tsindex a4825af1a..b24eb225b 100644--- a/src/features/debugger/hotswap.ts+++ b/src/features/debugger/hotswap.ts@@ -18,9 +18,8 @@ export function hotSwapSessions(): DebugSession[] {return Object.values(useDebug.getState().sessions).filter((s) => isLive(s) && !!s.caps?.hotCodeReplace);}-function plural(n: number, word: string) {- return `${n} ${word}${n === 1 ? "" : "es"}`;-}+/** "3 classes", translated per count (the sentence around it is translated on its own). */+const classesText = (n: number) => (n === 1 ? tx`${n} class` : tx`${n} classes`);/** Message for the reload result (IDEA wording). */export function hotSwapMessage(@@ -29,7 +28,7 @@ export function hotSwapMessage(): { level: "info" | "error"; title: string; body?: string } {if (errors.length) return { level: "error", title: "Hot Swap failed", body: errors.join("\n") };if (changed === 0) return { level: "info", title: "Loaded classes are up to date. Nothing to reload." };- return { level: "info", title: tx`${plural(changed, "class")} reloaded` };+ return { level: "info", title: tx`${classesText(changed)} reloaded` };}/** Compiles (unless `build` is false) and reloads changed classes into every Java debug session. */diff --git a/src/features/vcs/__tests__/pushResult.test.ts b/src/features/vcs/__tests__/remoteResults.test.tssimilarity index 59%rename from src/features/vcs/__tests__/pushResult.test.tsrename to src/features/vcs/__tests__/remoteResults.test.tsindex 4e1a73a43..fc32d8a0b 100644--- a/src/features/vcs/__tests__/pushResult.test.ts+++ b/src/features/vcs/__tests__/remoteResults.test.ts@@ -2,6 +2,8 @@ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";import type { BranchInfo } from "@/bindings";let branch: Partial<BranchInfo> = {};+/** What a pull brings in: the head moves to `c2`, with these changed files and commits. */+let pulled = { files: 0, commits: 0 };vi.mock("@tauri-apps/api/core", async (importOriginal) => ({...(await importOriginal<typeof import("@tauri-apps/api/core")>()),@@ -20,13 +22,18 @@ vi.mock("@/platform/ipc", async (importOriginal) => {status: "ok",data: { head: "main", headCommit: "c1", upstream: null, ahead: 0, behind: 0, operation: null, ...branch },}),- vcsRemote: async () => ({ status: "ok", data: null }),+ vcsRemote: async () => {+ if (pulled.commits) branch = { ...branch, headCommit: "c2" };+ return { status: "ok", data: null };+ },+ vcsDiffRevisions: async () => ({ status: "ok", data: Array.from({ length: pulled.files }, (_, i) => ({ i })) }),+ vcsLog: async () => ({ status: "ok", data: Array.from({ length: pulled.commits }, (_, i) => ({ i })) }),cancelRequest: async () => ({ status: "ok", data: null }),},};});-import { _resetI18nForTests, setLocale } from "@/platform/i18n";+import { _resetI18nForTests, setLocale, txTemplate } from "@/platform/i18n";import { provideNotificationService } from "@/workbench/contributions";import { runRemote } from "../ops";@@ -40,6 +47,7 @@ beforeEach(() => {afterEach(() => {branch = {};+ pulled = { files: 0, commits: 0 };_resetI18nForTests();});@@ -67,3 +75,25 @@ describe("push result notification", () => {expect(await pushTitle()).toBe("已推送 3 个提交到 origin/main");});});++const updateTitle = async () => {+ expect(await runRemote({ op: "pull" } as never, undefined, ["/p"])).toBe(true);+ return notes.at(-1)!.title;+};++describe("Update Project result notification", () => {+ it("counts the files and commits that came in", async () => {+ pulled = { files: 3, commits: 2 };+ expect(await updateTitle()).toBe("3 files updated in 2 commits");+ branch = {};+ pulled = { files: 1, commits: 1 };+ expect(await updateTitle()).toBe("1 file updated in 1 commit");+ });++ it("translates the counts inside the sentence", async () => {+ await setLocale("zh");+ pulled = { files: 3, commits: 2 };+ // Notification titles are translated as they are shown.+ expect(txTemplate(await updateTitle())).toBe("已在 2 个提交中更新 3 个文件");+ });+});diff --git a/src/features/vcs/ops.ts b/src/features/vcs/ops.tsindex 8e81fd0c2..17d442e9a 100644--- a/src/features/vcs/ops.ts+++ b/src/features/vcs/ops.ts@@ -266,7 +266,9 @@ const headCommit = (repo: string | null) =>() => null,);-const plural = (n: number, word: string) => `${n} ${word}${n === 1 ? "" : "s"}`;+/** Counts for a translated sentence: each variant is its own source text, as "{count} files". */+const filesText = (n: number) => (n === 1 ? tx`${n} file` : tx`${n} files`);+const commitsText = (n: number) => (n === 1 ? tx`${n} commit` : tx`${n} commits`);/** "Pushed 3 commits to origin/main", translated per count. */const pushedTitle = (n: number, to: string) =>@@ -304,7 +306,7 @@ async function notifyUpdated(updated: readonly UpdatedRange[]) {group: "vcs",level: "info",key: "vcs.remote",- title: `${plural(files, "file")} updated in ${plural(commits, "commit")}`,+ title: `${filesText(files)} updated in ${commitsText(commits)}`,actions: [{label: "View Commits",diff --git a/src/platform/locales/text/zh.json b/src/platform/locales/text/zh.jsonindex 2e00073a9..0522011de 100644--- a/src/platform/locales/text/zh.json+++ b/src/platform/locales/text/zh.json@@ -3781,7 +3781,7 @@"Select two commits to compare": "选择两个提交进行比较","Label '{value}' added to Local History": "已将标签 '{value}' 添加到本地历史记录","{doneTitle} successful": "{doneTitle}成功",- "{file} updated in {commit}": "已在 {commit} 中更新 {file}",+ "{file} updated in {commit}": "已在 {commit}中更新 {file}","Shelved {length} file": "已搁置 {length} 个文件","Shelved {length} files": "已搁置 {length} 个文件","{what}: {length} file with conflicts": "{what}:{length} 个文件存在冲突",@@ -3943,6 +3943,8 @@"Cannot copy the DDL": "无法复制 DDL","Start the remote JVM with -agentlib:jdwp=transport=dt_socket,server=n,address={host}:{port},suspend=y": "使用 -agentlib:jdwp=transport=dt_socket,server=n,address={host}:{port},suspend=y 启动远程 JVM","{class} reloaded": "已重新加载 {class}",+ "{count} class": "{count} 个类",+ "{count} classes": "{count} 个类","The JavaScript debugger (vscode-js-debug) is not installed": "JavaScript 调试器 (vscode-js-debug) 未安装","Delve is not installed": "Delve 未安装","CodeLLDB is not installed": "CodeLLDB 未安装",@@ -5147,6 +5149,7 @@"Mark as Not Viewed": "标记为未查看","Mark All as Viewed": "全部标记为已查看","Mark All as Not Viewed": "全部标记为未查看",+ "{count} commit": "{count} 个提交","{count} commits": "{count} 个提交","1 commit": "1 个提交","All commits ({count})": "所有提交 ({count})",