Skip to content

Commit

Permalink
feat(l10n): add localization support to prompts in commands.ts #44
Browse files Browse the repository at this point in the history
The commit introduces localization to the prompts in the commands.ts file. This is achieved by using the l10n.t function from vscode to translate the prompt messages. This will help in providing a better user experience for non-English speakers.
  • Loading branch information
phodal committed May 25, 2024
1 parent ae184db commit 003106c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
4 changes: 3 additions & 1 deletion l10n/bundle.l10n.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@
"lang.java.prompt.testForController": "Use appropriate Spring test annotations such as `@MockBean`, `@Autowired`, `@WebMvcTest`, `@DataJpaTest`, `@AutoConfigureTestDatabase`, `@AutoConfigureMockMvc`, `@SpringBootTest` etc",
"lang.java.prompt.testForService": "Follow the common Spring code style by using the AssertJ library.\nAssume that the database is empty before each test and create valid entities with consideration for data constraints (jakarta.validation.constraints).",
"lang.java.prompt.useJunit4": "This project uses JUnit 4, you should import `org.junit.Test` and use `@Test` annotation.",
"lang.java.prompt.useJunit5": "This project uses JUnit 5, you should import `org.junit.jupiter.api.Test` and use `@Test` annotation."
"lang.java.prompt.useJunit5": "This project uses JUnit 5, you should import `org.junit.jupiter.api.Test` and use `@Test` annotation.",
"How do I fix this problem in the above code?": "How do I fix this problem in the above code?",
"I got the following error, can you please help explain how to fix it?": "I got the following error, can you please help explain how to fix it?"
}
4 changes: 3 additions & 1 deletion l10n/bundle.l10n.zh-cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@
"lang.java.prompt.testForController": "Use appropriate Spring test annotations such as `@MockBean`, `@Autowired`, `@WebMvcTest`, `@DataJpaTest`, `@AutoConfigureTestDatabase`, `@AutoConfigureMockMvc`, `@SpringBootTest` etc",
"lang.java.prompt.testForService": "Follow the common Spring code style by using the AssertJ library.\nAssume that the database is empty before each test and create valid entities with consideration for data constraints (jakarta.validation.constraints).",
"lang.java.prompt.useJunit4": "This project uses JUnit 4, you should import `org.junit.Test` and use `@Test` annotation.",
"lang.java.prompt.useJunit5": "This project uses JUnit 5, you should import `org.junit.jupiter.api.Test` and use `@Test` annotation."
"lang.java.prompt.useJunit5": "This project uses JUnit 5, you should import `org.junit.jupiter.api.Test` and use `@Test` annotation.",
"How do I fix this problem in the above code?": "请帮我修复下面代码中的问题:",
"I got the following error, can you please help explain how to fix it?": "我遇到了以下错误,请帮我解释如何修复它?"
}
11 changes: 5 additions & 6 deletions src/commands/commands.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as vscode from "vscode";
import { l10n } from "vscode";

import { AutoDevExtension } from "../AutoDevExtension";
import { NamedElement } from "../editor/ast/NamedElement";
Expand All @@ -22,9 +23,7 @@ const commandsMap: (extension: AutoDevExtension) => AutoDevCommandOperation = (e
let language = vscode.window.activeTextEditor?.document.languageId ?? "";

extension.sidebar.webviewProtocol?.request("newSessionWithPrompt", {
prompt: `${
edit ? "/edit " : ""
}${code}\n\nHow do I fix this problem in the above code?:
prompt: `${edit ? "/edit " : ""}${code}\n\n${l10n.t("How do I fix this problem in the above code?")}:
\`\`\`${language}
${message}
\`\`\`
Expand All @@ -43,15 +42,15 @@ ${message}
vscode.commands.executeCommand("autodev.autodevGUIView.focus");
const terminalContents = await extension.ideAction.getTerminalContents(1);
extension.sidebar.webviewProtocol?.request("newSessionWithPrompt", {
prompt: `I got the following error, can you please help explain how to fix it?\n\n${terminalContents.trim()}`,
prompt: `${l10n.t("I got the following error, can you please help explain how to fix it?")}\n\n${terminalContents.trim()}`,
});

vscode.commands.executeCommand("autodev.autodevGUIView.focus");
},
[AutoDevCommand.TerminalExplainContextMenu]: async () => {
const terminalContents = await extension.ideAction.getTerminalContents(1);
extension.sidebar.webviewProtocol?.request("newSessionWithPrompt", {
prompt: `I got the following error, can you please help explain how to fix it?\n\n${terminalContents.trim()}`,
prompt: `${l10n.t("I got the following error, can you please help explain how to fix it?")}\n\n${terminalContents.trim()}`,
});

vscode.commands.executeCommand("autodev.autodevGUIView.focus");
Expand Down Expand Up @@ -139,7 +138,7 @@ ${input}
}

extension.sidebar.webviewProtocol?.request("newSessionWithPrompt", {
prompt: `How do I fix this problem in the above code?: ${input}`,
prompt: `\`${l10n.t("I got the following error, can you please help explain how to fix it?")}: ${input}`,
});

vscode.commands.executeCommand("autodev.autodevGUIView.focus");
Expand Down

0 comments on commit 003106c

Please sign in to comment.