Skip to content

🙌 OpenHands: AI-Driven Development

fix: localize ChatAddFileButton aria-label (#462)

Hiep Le818b7881912f
diff --git a/__tests__/components/chat/chat-add-file-button.test.tsx b/__tests__/components/chat/chat-add-file-button.test.tsx
new file mode 100644
index 0000000000..b09ee5a3cf
--- /dev/null
+++ b/__tests__/components/chat/chat-add-file-button.test.tsx
@@ -0,0 +1,49 @@
+import { render, screen } from "@testing-library/react";
+import userEvent from "@testing-library/user-event";
+import { describe, expect, it, vi } from "vitest";
+import { ChatAddFileButton } from "#/components/features/chat/chat-add-file-button";
+import { I18nKey } from "#/i18n/declaration";
+
+describe("ChatAddFileButton", () => {
+ it("uses the translated aria-label key instead of a hardcoded string", () => {
+ render(<ChatAddFileButton handleFileIconClick={vi.fn()} />);
+
+ const button = screen.getByTestId("paperclip-icon");
+ expect(button).toHaveAttribute("aria-label", I18nKey.CHAT_INTERFACE$ADD_FILE);
+ expect(button).not.toHaveAttribute("aria-label", "Add file");
+ });
+
+ it("invokes handleFileIconClick when clicked", async () => {
+ const user = userEvent.setup();
+ const handleFileIconClick = vi.fn();
+
+ render(<ChatAddFileButton handleFileIconClick={handleFileIconClick} />);
+
+ await user.click(
+ screen.getByLabelText(I18nKey.CHAT_INTERFACE$ADD_FILE),
+ );
+ expect(handleFileIconClick).toHaveBeenCalledTimes(1);
+ });
+
+ it("disables the button and suppresses clicks when disabled", async () => {
+ const user = userEvent.setup();
+ const handleFileIconClick = vi.fn();
+
+ render(
+ <ChatAddFileButton
+ handleFileIconClick={handleFileIconClick}
+ disabled
+ />,
+ );
+
+ const button = screen.getByTestId("paperclip-icon");
+ expect(button).toBeDisabled();
+ expect(button).toHaveAttribute(
+ "aria-label",
+ I18nKey.CHAT_INTERFACE$ADD_FILE,
+ );
+
+ await user.click(button);
+ expect(handleFileIconClick).not.toHaveBeenCalled();
+ });
+});
diff --git a/src/components/features/chat/chat-add-file-button.tsx b/src/components/features/chat/chat-add-file-button.tsx
index 1fc2998948..c26f54dec0 100644
--- a/src/components/features/chat/chat-add-file-button.tsx
+++ b/src/components/features/chat/chat-add-file-button.tsx
@@ -1,4 +1,6 @@
import { Plus } from "lucide-react";
+import { useTranslation } from "react-i18next";
+import { I18nKey } from "#/i18n/declaration";
import { cn } from "#/utils/utils";
export interface ChatAddFileButtonProps {
@@ -10,6 +12,8 @@ export function ChatAddFileButton({
handleFileIconClick,
disabled = false,
}: ChatAddFileButtonProps) {
+ const { t } = useTranslation("openhands");
+
return (
<button
type="button"
@@ -19,7 +23,7 @@ export function ChatAddFileButton({
? "cursor-not-allowed text-[#6B7280]"
: "cursor-pointer text-[#959CB2] hover:text-white hover:bg-white/10",
)}
- aria-label="Add file"
+ aria-label={t(I18nKey.CHAT_INTERFACE$ADD_FILE)}
data-testid="paperclip-icon"
onClick={handleFileIconClick}
disabled={disabled}
diff --git a/src/i18n/translation.json b/src/i18n/translation.json
index 4ab421eb8e..602e2692ea 100644
--- a/src/i18n/translation.json
+++ b/src/i18n/translation.json
@@ -9808,6 +9808,23 @@
"uk": "Завантажити зображення",
"ca": "Carrega una imatge"
},
+ "CHAT_INTERFACE$ADD_FILE": {
+ "en": "Add file",
+ "ja": "ファイルを追加",
+ "zh-CN": "添加文件",
+ "zh-TW": "新增檔案",
+ "ko-KR": "파일 추가",
+ "no": "Legg til fil",
+ "it": "Aggiungi file",
+ "pt": "Adicionar arquivo",
+ "es": "Añadir archivo",
+ "ar": "إضافة ملف",
+ "fr": "Ajouter un fichier",
+ "tr": "Dosya ekle",
+ "de": "Datei hinzufügen",
+ "uk": "Додати файл",
+ "ca": "Afegeix un fitxer"
+ },
"CHAT_INTERFACE$INITIAL_MESSAGE": {
"en": "Hi! I'm OpenHands, an AI Software Engineer. What would you like to build with me today?",
"zh-CN": "你好!我是 OpenHands,一名 AI 软件工程师。今天想和我一起编写什么程序呢?",