Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

Voice: keep a saved language the picker does not list visible in the picker

AdityaUmale1a142023783a
diff --git a/src/components/VoiceHearingSetting.test.ts b/src/components/VoiceHearingSetting.test.ts
new file mode 100644
index 0000000000..5490962f6e
--- /dev/null
+++ b/src/components/VoiceHearingSetting.test.ts
@@ -0,0 +1,19 @@
+import { describe, expect, it } from "vitest";
+import { HEAR_LANGUAGES, languageOptions } from "./VoiceHearingSetting";
+
+describe("languageOptions", () => {
+ it("offers the listed languages once each", () => {
+ const codes = languageOptions("es").map((option) => option.code);
+ expect(codes).toHaveLength(HEAR_LANGUAGES.length);
+ expect(codes.filter((code) => code === "es")).toHaveLength(1);
+ });
+
+ it("adds a saved language the list does not offer, so the picker shows it", () => {
+ expect(languageOptions("cy").map((option) => option.code)).toContain("cy");
+ expect(languageOptions("spa").map((option) => option.code)).toContain("spa");
+ });
+
+ it("adds nothing for automatic detection", () => {
+ expect(languageOptions("")).toHaveLength(HEAR_LANGUAGES.length);
+ });
+});
diff --git a/src/components/VoiceHearingSetting.tsx b/src/components/VoiceHearingSetting.tsx
index c2e6855e7f..ea565c5f86 100644
--- a/src/components/VoiceHearingSetting.tsx
+++ b/src/components/VoiceHearingSetting.tsx
@@ -11,14 +11,16 @@ export const HEAR_LANGUAGES = [
"no", "fa", "pl", "pt", "ro", "ru", "es", "sv", "th", "tr", "uk", "ur", "vi",
] as const;
-function languageOptions(): Array<{ code: string; name: string }> {
+/** The picker's languages, plus the saved code when it is one the list does not offer, so the picker never shows "automatic" for it. */
+export function languageOptions(saved = ""): Array<{ code: string; name: string }> {
let names: Intl.DisplayNames | null = null;
try {
names = new Intl.DisplayNames([intlLocale()], { type: "language" });
} catch {
// Without display names the codes themselves are shown.
}
- return HEAR_LANGUAGES.map((code) => ({ code, name: names?.of(code) ?? code })).sort((a, b) => a.name.localeCompare(b.name, intlLocale()));
+ const codes: readonly string[] = saved && !(HEAR_LANGUAGES as readonly string[]).includes(saved) ? [...HEAR_LANGUAGES, saved] : HEAR_LANGUAGES;
+ return codes.map((code) => ({ code, name: names?.of(code) ?? code })).sort((a, b) => a.name.localeCompare(b.name, intlLocale()));
}
/** "Hear me with ElevenLabs": dictation and Take turns go to Scribe with the person's own key, in the language they pick.
@@ -43,7 +45,7 @@ export function VoiceHearingSetting() {
const picker = (
<Select size="sm" aria-label={t("voice.hearLanguage")} value={language} disabled={saving} onChange={(event) => save({ hearLanguage: event.target.value })}>
<option value="">{t("voice.hearLanguage.auto")}</option>
- {languageOptions().map(({ code, name }) => <option key={code} value={code}>{name}</option>)}
+ {languageOptions(language).map(({ code, name }) => <option key={code} value={code}>{name}</option>)}
</Select>
);
const alert = error ? <span role="alert" className="text-danger">{error}</span> : undefined;