Skip to content

Commit e27a42b

Browse files
authored
feat: localize code action commands (#334) (#339)
1 parent 57d4817 commit e27a42b

20 files changed

Lines changed: 142 additions & 24 deletions

src/activate/CodeActionProvider.ts

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,11 @@
11
import * as vscode from "vscode"
22

3-
import { CodeActionName, CodeActionId } from "@roo-code/types"
3+
import { CodeActionId } from "@roo-code/types"
44
import { Package } from "../shared/package"
55

66
import { getCodeActionCommand } from "../utils/commands"
77
import { EditorUtils } from "../integrations/editor/EditorUtils"
8-
9-
export const TITLES: Record<CodeActionName, string> = {
10-
EXPLAIN: "Explain with Zoo Code",
11-
FIX: "Fix with Zoo Code",
12-
IMPROVE: "Improve with Zoo Code",
13-
ADD_TO_CONTEXT: "Add to Zoo Code",
14-
NEW_TASK: "New Roo Code Task",
15-
} as const
8+
import { t } from "../i18n"
169

1710
export class CodeActionProvider implements vscode.CodeActionProvider {
1811
public static readonly providedCodeActionKinds = [
@@ -51,12 +44,17 @@ export class CodeActionProvider implements vscode.CodeActionProvider {
5144
const actions: vscode.CodeAction[] = []
5245

5346
actions.push(
54-
this.createAction(TITLES.ADD_TO_CONTEXT, vscode.CodeActionKind.QuickFix, "addToContext", [
55-
filePath,
56-
effectiveRange.text,
57-
effectiveRange.range.start.line + 1,
58-
effectiveRange.range.end.line + 1,
59-
]),
47+
this.createAction(
48+
t("common:codeActions.addToContext"),
49+
vscode.CodeActionKind.QuickFix,
50+
"addToContext",
51+
[
52+
filePath,
53+
effectiveRange.text,
54+
effectiveRange.range.start.line + 1,
55+
effectiveRange.range.end.line + 1,
56+
],
57+
),
6058
)
6159

6260
if (context.diagnostics.length > 0) {
@@ -66,7 +64,7 @@ export class CodeActionProvider implements vscode.CodeActionProvider {
6664

6765
if (relevantDiagnostics.length > 0) {
6866
actions.push(
69-
this.createAction(TITLES.FIX, vscode.CodeActionKind.QuickFix, "fixCode", [
67+
this.createAction(t("common:codeActions.fix"), vscode.CodeActionKind.QuickFix, "fixCode", [
7068
filePath,
7169
effectiveRange.text,
7270
effectiveRange.range.start.line + 1,
@@ -77,7 +75,7 @@ export class CodeActionProvider implements vscode.CodeActionProvider {
7775
}
7876
} else {
7977
actions.push(
80-
this.createAction(TITLES.EXPLAIN, vscode.CodeActionKind.QuickFix, "explainCode", [
78+
this.createAction(t("common:codeActions.explain"), vscode.CodeActionKind.QuickFix, "explainCode", [
8179
filePath,
8280
effectiveRange.text,
8381
effectiveRange.range.start.line + 1,
@@ -86,7 +84,7 @@ export class CodeActionProvider implements vscode.CodeActionProvider {
8684
)
8785

8886
actions.push(
89-
this.createAction(TITLES.IMPROVE, vscode.CodeActionKind.QuickFix, "improveCode", [
87+
this.createAction(t("common:codeActions.improve"), vscode.CodeActionKind.QuickFix, "improveCode", [
9088
filePath,
9189
effectiveRange.text,
9290
effectiveRange.range.start.line + 1,

src/activate/__tests__/CodeActionProvider.spec.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,19 @@ import * as vscode from "vscode"
33

44
import { EditorUtils } from "../../integrations/editor/EditorUtils"
55

6-
import { CodeActionProvider, TITLES } from "../CodeActionProvider"
6+
import { CodeActionProvider } from "../CodeActionProvider"
7+
8+
vi.mock("../../i18n", () => ({
9+
t: vi.fn((key: string) => {
10+
const translations: Record<string, string> = {
11+
"common:codeActions.explain": "Explain with Zoo Code",
12+
"common:codeActions.fix": "Fix with Zoo Code",
13+
"common:codeActions.improve": "Improve with Zoo Code",
14+
"common:codeActions.addToContext": "Add to Zoo Code",
15+
}
16+
return translations[key] || key
17+
}),
18+
}))
719

820
vi.mock("vscode", () => ({
921
CodeAction: vi.fn().mockImplementation((title, kind) => ({
@@ -74,9 +86,9 @@ describe("CodeActionProvider", () => {
7486
const actions = provider.provideCodeActions(mockDocument, mockRange, mockContext)
7587

7688
expect(actions).toHaveLength(3)
77-
expect((actions as any)[0].title).toBe(TITLES.ADD_TO_CONTEXT)
78-
expect((actions as any)[1].title).toBe(TITLES.EXPLAIN)
79-
expect((actions as any)[2].title).toBe(TITLES.IMPROVE)
89+
expect((actions as any)[0].title).toBe("Add to Zoo Code")
90+
expect((actions as any)[1].title).toBe("Explain with Zoo Code")
91+
expect((actions as any)[2].title).toBe("Improve with Zoo Code")
8092
})
8193

8294
it("should provide fix action instead of fix logic when diagnostics exist", () => {
@@ -87,8 +99,8 @@ describe("CodeActionProvider", () => {
8799
const actions = provider.provideCodeActions(mockDocument, mockRange, mockContext)
88100

89101
expect(actions).toHaveLength(2)
90-
expect((actions as any).some((a: any) => a.title === `${TITLES.FIX}`)).toBe(true)
91-
expect((actions as any).some((a: any) => a.title === `${TITLES.ADD_TO_CONTEXT}`)).toBe(true)
102+
expect((actions as any).some((a: any) => a.title === "Fix with Zoo Code")).toBe(true)
103+
expect((actions as any).some((a: any) => a.title === "Add to Zoo Code")).toBe(true)
92104
})
93105

94106
it("should return empty array when no effective range", () => {

src/i18n/locales/ca/common.json

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/i18n/locales/de/common.json

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/i18n/locales/en/common.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,5 +259,11 @@
259259
"connected": "Zoo Code: Successfully connected! You can now use Zoo Code as your AI provider.",
260260
"disconnected": "Zoo Code: Disconnected successfully."
261261
}
262+
},
263+
"codeActions": {
264+
"explain": "Explain with Zoo Code",
265+
"fix": "Fix with Zoo Code",
266+
"improve": "Improve with Zoo Code",
267+
"addToContext": "Add to Zoo Code"
262268
}
263269
}

src/i18n/locales/es/common.json

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/i18n/locales/fr/common.json

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/i18n/locales/hi/common.json

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/i18n/locales/id/common.json

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/i18n/locales/it/common.json

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)