Skip to content

🙌 OpenHands: AI-Driven Development

chore: localize hardcoded strings in BtwMessages (#702)

Hiep Le196d44f26031
diff --git a/__tests__/components/chat/btw-messages.test.tsx b/__tests__/components/chat/btw-messages.test.tsx
index 38956aac8c..048cefbdcc 100644
--- a/__tests__/components/chat/btw-messages.test.tsx
+++ b/__tests__/components/chat/btw-messages.test.tsx
@@ -2,6 +2,7 @@ import { render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { beforeEach, describe, expect, it } from "vitest";
import { BtwMessages } from "#/components/features/chat/btw-messages";
+import { I18nKey } from "#/i18n/declaration";
import { useBtwStore } from "#/stores/btw-store";
const CONV = "conv-1";
@@ -18,7 +19,11 @@ describe("<BtwMessages />", () => {
render(<BtwMessages conversationId={CONV} />);
expect(screen.getByText("why?")).toBeInTheDocument();
expect(screen.getByTestId("btw-spinner")).toBeInTheDocument();
- expect(screen.queryByRole("button", { name: /got it/i })).toBeNull();
+ expect(
+ screen.queryByRole("button", {
+ name: I18nKey.CHAT_INTERFACE$BTW_GOT_IT,
+ }),
+ ).toBeNull();
});
it("renders the response and a Got it button that dismisses on click", async () => {
@@ -27,7 +32,11 @@ describe("<BtwMessages />", () => {
const user = userEvent.setup();
render(<BtwMessages conversationId={CONV} />);
expect(screen.getByText(/because/i)).toBeInTheDocument();
- await user.click(screen.getByRole("button", { name: /got it/i }));
+ await user.click(
+ screen.getByRole("button", {
+ name: I18nKey.CHAT_INTERFACE$BTW_GOT_IT,
+ }),
+ );
expect(entriesFor(CONV)).toEqual([]);
});
@@ -36,4 +45,26 @@ describe("<BtwMessages />", () => {
const { container } = render(<BtwMessages conversationId={CONV} />);
expect(container).toBeEmptyDOMElement();
});
+
+ it("renders BTW prefix and pending details through translation keys", async () => {
+ useBtwStore.getState().addPending(CONV, "why?");
+ const user = userEvent.setup();
+ render(<BtwMessages conversationId={CONV} />);
+ expect(
+ screen.getByText(I18nKey.CHAT_INTERFACE$BTW_PREFIX),
+ ).toBeInTheDocument();
+ await user.click(screen.getByRole("button", { name: /expand/i }));
+ expect(
+ screen.getByText(I18nKey.CHAT_INTERFACE$BTW_WAITING_FOR_ANSWER),
+ ).toBeInTheDocument();
+ });
+
+ it("does not render the pending-state translation key once the entry has resolved", () => {
+ const id = useBtwStore.getState().addPending(CONV, "why?");
+ useBtwStore.getState().resolve(CONV, id, "because");
+ render(<BtwMessages conversationId={CONV} />);
+ expect(
+ screen.queryByText(I18nKey.CHAT_INTERFACE$BTW_WAITING_FOR_ANSWER),
+ ).toBeNull();
+ });
});
diff --git a/src/components/features/chat/btw-messages.tsx b/src/components/features/chat/btw-messages.tsx
index 8dfcae4ac2..c4a72e20e8 100644
--- a/src/components/features/chat/btw-messages.tsx
+++ b/src/components/features/chat/btw-messages.tsx
@@ -1,8 +1,11 @@
+import { useTranslation } from "react-i18next";
import CheckCircle from "#/icons/check-circle-solid.svg?react";
+import { I18nKey } from "#/i18n/declaration";
import { useBtwStore } from "#/stores/btw-store";
import { GenericEventMessage } from "./generic-event-message";
function GotItButton({ onClick }: { onClick: () => void }) {
+ const { t } = useTranslation("openhands");
return (
<button
type="button"
@@ -10,8 +13,7 @@ function GotItButton({ onClick }: { onClick: () => void }) {
className="flex items-center gap-1.5 px-3 py-1 rounded-full text-xs font-medium text-success bg-success/10 hover:bg-success/20 border border-success/30 transition-colors"
>
<CheckCircle className="w-3.5 h-3.5 fill-success" />
- {/* eslint-disable-next-line i18next/no-literal-string */}
- <span>Got it</span>
+ <span>{t(I18nKey.CHAT_INTERFACE$BTW_GOT_IT)}</span>
</button>
);
}
@@ -21,6 +23,7 @@ export interface BtwMessagesProps {
}
export function BtwMessages({ conversationId }: BtwMessagesProps) {
+ const { t } = useTranslation("openhands");
const entriesById = useBtwStore((s) => s.entriesByConversation);
const dismiss = useBtwStore((s) => s.dismiss);
const entries = conversationId ? (entriesById[conversationId] ?? []) : [];
@@ -36,8 +39,9 @@ export function BtwMessages({ conversationId }: BtwMessagesProps) {
key={entry.id}
title={
<span className="flex items-center gap-2">
- {/* eslint-disable-next-line i18next/no-literal-string */}
- <span className="opacity-60">BTW:</span>
+ <span className="opacity-60">
+ {t(I18nKey.CHAT_INTERFACE$BTW_PREFIX)}
+ </span>
<span>{entry.question}</span>
{isPending && (
<span
@@ -49,7 +53,7 @@ export function BtwMessages({ conversationId }: BtwMessagesProps) {
}
details={
isPending
- ? "Waiting for the agent's answer…"
+ ? t(I18nKey.CHAT_INTERFACE$BTW_WAITING_FOR_ANSWER)
: (entry.response ?? "")
}
initiallyExpanded={!isPending}
diff --git a/src/i18n/translation.json b/src/i18n/translation.json
index 2a23c55aa3..1068268ae9 100644
--- a/src/i18n/translation.json
+++ b/src/i18n/translation.json
@@ -8516,6 +8516,57 @@
"uk": "Налаштування оновлено",
"ca": "Configuració actualitzada"
},
+ "CHAT_INTERFACE$BTW_PREFIX": {
+ "en": "BTW:",
+ "ja": "ところで:",
+ "zh-CN": "顺便说一下:",
+ "zh-TW": "順便一提:",
+ "ko-KR": "참고로:",
+ "no": "Forresten:",
+ "it": "A proposito:",
+ "pt": "A propósito:",
+ "es": "Por cierto:",
+ "ar": "بالمناسبة:",
+ "fr": "Au fait :",
+ "tr": "Bu arada:",
+ "de": "Übrigens:",
+ "uk": "До речі:",
+ "ca": "Per cert:"
+ },
+ "CHAT_INTERFACE$BTW_GOT_IT": {
+ "en": "Got it",
+ "ja": "了解",
+ "zh-CN": "知道了",
+ "zh-TW": "了解",
+ "ko-KR": "알겠습니다",
+ "no": "Forstått",
+ "it": "Capito",
+ "pt": "Entendi",
+ "es": "Entendido",
+ "ar": "حسناً",
+ "fr": "Compris",
+ "tr": "Anladım",
+ "de": "Verstanden",
+ "uk": "Зрозуміло",
+ "ca": "Entès"
+ },
+ "CHAT_INTERFACE$BTW_WAITING_FOR_ANSWER": {
+ "en": "Waiting for the agent's answer…",
+ "ja": "エージェントの回答を待機中…",
+ "zh-CN": "正在等待智能体的回答…",
+ "zh-TW": "正在等待智慧代理的回答…",
+ "ko-KR": "에이전트의 답변을 기다리는 중…",
+ "no": "Venter på agentens svar…",
+ "it": "In attesa della risposta dell'agente…",
+ "pt": "Aguardando a resposta do agente…",
+ "es": "Esperando la respuesta del agente…",
+ "ar": "في انتظار إجابة الوكيل…",
+ "fr": "En attente de la réponse de l'agent…",
+ "tr": "Ajanın yanıtı bekleniyor…",
+ "de": "Warte auf die Antwort des Agenten…",
+ "uk": "Очікування відповіді агента…",
+ "ca": "Esperant la resposta de l'agent…"
+ },
"CHAT_INTERFACE$MESSAGE_SENDING": {
"en": "Sending...",
"ja": "送信中...",