Skip to content

Commit 7e65f6f

Browse files
committed
feat: internationalize error messages for custom error titles
- Added i18n support for error titles and messages in applyDiffTool, insertContentTool, and Task.ts - Added English translations for new error messages in tools.json - Translated error messages to all 18 supported languages (ca, de, es, fr, hi, id, it, ja, ko, nl, pl, pt-BR, ru, tr, vi, zh-CN, zh-TW) - Updated code to use i18n keys instead of hardcoded strings - Fixed tests to work with i18n keys - All translations validated with find-missing-translations.js script
1 parent eef6c03 commit 7e65f6f

File tree

22 files changed

+373
-10
lines changed

22 files changed

+373
-10
lines changed

src/core/task/Task.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,18 +1164,21 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
11641164
}
11651165

11661166
async sayAndCreateMissingParamError(toolName: ToolName, paramName: string, relPath?: string) {
1167+
const relPathFormatted = relPath ? ` for '${relPath.toPosix()}'` : ""
11671168
await this.say(
11681169
"error",
1169-
`Roo tried to use ${toolName}${
1170-
relPath ? ` for '${relPath.toPosix()}'` : ""
1171-
} without value for required parameter '${paramName}'. Retrying...`,
1170+
t("tools:common.errors.missingParameterMessage", {
1171+
toolName,
1172+
relPath: relPathFormatted,
1173+
paramName,
1174+
}),
11721175
undefined,
11731176
undefined,
11741177
undefined,
11751178
undefined,
11761179
{
11771180
metadata: {
1178-
title: "Missing Parameter Error",
1181+
title: t("tools:common.errors.missingParameter"),
11791182
},
11801183
},
11811184
)

src/core/tools/__tests__/insertContentTool.spec.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,22 @@ vi.mock("../../ignore/RooIgnoreController", () => ({
4646
},
4747
}))
4848

49+
vi.mock("../../../i18n", () => ({
50+
t: vi.fn((key: string, params?: any) => {
51+
// Return the key without the namespace prefix for testing
52+
const keyWithoutNamespace = key.replace(/^[^:]+:/, "")
53+
if (params) {
54+
// Simple parameter replacement for testing
55+
let result = keyWithoutNamespace
56+
Object.entries(params).forEach(([key, value]) => {
57+
result = result.replace(`{{${key}}}`, String(value))
58+
})
59+
return result
60+
}
61+
return keyWithoutNamespace
62+
}),
63+
}))
64+
4965
describe("insertContentTool", () => {
5066
const testFilePath = "test/file.txt"
5167
// Use a consistent mock absolute path for testing
@@ -228,14 +244,14 @@ describe("insertContentTool", () => {
228244
expect(mockCline.recordToolError).toHaveBeenCalledWith("insert_content")
229245
expect(mockCline.say).toHaveBeenCalledWith(
230246
"error",
231-
expect.stringContaining("non-existent file"),
247+
"insertContent.errors.cannotInsertIntoNonExistent",
232248
undefined,
233249
undefined,
234250
undefined,
235251
undefined,
236252
expect.objectContaining({
237253
metadata: expect.objectContaining({
238-
title: "Invalid Line Number",
254+
title: "insertContent.errors.invalidLineNumber",
239255
}),
240256
}),
241257
)

src/core/tools/applyDiffTool.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { fileExistsAtPath } from "../../utils/fs"
1313
import { RecordSource } from "../context-tracking/FileContextTrackerTypes"
1414
import { unescapeHtmlEntities } from "../../utils/text-normalization"
1515
import { EXPERIMENT_IDS, experiments } from "../../shared/experiments"
16+
import { t } from "../../i18n"
1617

1718
export async function applyDiffToolLegacy(
1819
cline: Task,
@@ -82,9 +83,9 @@ export async function applyDiffToolLegacy(
8283
if (!fileExists) {
8384
cline.consecutiveMistakeCount++
8485
cline.recordToolError("apply_diff")
85-
const formattedError = `File does not exist at path: ${absolutePath}\n\n<error_details>\nThe specified file could not be found. Please verify the file path and try again.\n</error_details>`
86+
const formattedError = `${t("tools:applyDiff.errors.fileDoesNotExist", { path: absolutePath })}\n\n<error_details>\n${t("tools:applyDiff.errors.fileDoesNotExistDetails")}\n</error_details>`
8687
await cline.say("error", formattedError, undefined, undefined, undefined, undefined, {
87-
metadata: { title: "File Not Found" },
88+
metadata: { title: t("tools:applyDiff.errors.fileNotFound") },
8889
})
8990
pushToolResult(formattedError)
9091
return

src/core/tools/insertContentTool.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { fileExistsAtPath } from "../../utils/fs"
1212
import { insertGroups } from "../diff/insert-groups"
1313
import { DEFAULT_WRITE_DELAY_MS } from "@roo-code/types"
1414
import { EXPERIMENT_IDS, experiments } from "../../shared/experiments"
15+
import { t } from "../../i18n"
1516

1617
export async function insertContentTool(
1718
cline: Task,
@@ -86,9 +87,9 @@ export async function insertContentTool(
8687
if (lineNumber > 1) {
8788
cline.consecutiveMistakeCount++
8889
cline.recordToolError("insert_content")
89-
const formattedError = `Cannot insert content at line ${lineNumber} into a non-existent file. For new files, 'line' must be 0 (to append) or 1 (to insert at the beginning).`
90+
const formattedError = t("tools:insertContent.errors.cannotInsertIntoNonExistent", { lineNumber })
9091
await cline.say("error", formattedError, undefined, undefined, undefined, undefined, {
91-
metadata: { title: "Invalid Line Number" },
92+
metadata: { title: t("tools:insertContent.errors.invalidLineNumber") },
9293
})
9394
pushToolResult(formattedError)
9495
return

src/i18n/locales/ca/tools.json

Lines changed: 19 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/tools.json

Lines changed: 19 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/tools.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,24 @@
1414
"errors": {
1515
"policy_restriction": "Failed to create new task due to policy restrictions."
1616
}
17+
},
18+
"applyDiff": {
19+
"errors": {
20+
"fileNotFound": "File Not Found",
21+
"fileDoesNotExist": "File does not exist at path: {{path}}",
22+
"fileDoesNotExistDetails": "The specified file could not be found. Please verify the file path and try again."
23+
}
24+
},
25+
"insertContent": {
26+
"errors": {
27+
"invalidLineNumber": "Invalid Line Number",
28+
"cannotInsertIntoNonExistent": "Cannot insert content at line {{lineNumber}} into a non-existent file. For new files, 'line' must be 0 (to append) or 1 (to insert at the beginning)."
29+
}
30+
},
31+
"common": {
32+
"errors": {
33+
"missingParameter": "Missing Parameter Error",
34+
"missingParameterMessage": "Roo tried to use {{toolName}}{{relPath}} without value for required parameter '{{paramName}}'. Retrying..."
35+
}
1736
}
1837
}

src/i18n/locales/es/tools.json

Lines changed: 19 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/tools.json

Lines changed: 19 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/tools.json

Lines changed: 19 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)