From 7c956f09bae08093204ec5ebb4f366040b7b2c89 Mon Sep 17 00:00:00 2001 From: Gabriel Taveira Date: Tue, 20 Oct 2026 12:13:37 -0300 Subject: [PATCH 1/6] feat(mobile): voice input can transcribe in a chosen language Dictation always used the device locale, so someone whose iPhone is in English but who speaks Portuguese got garbage. Add an optional voiceInputLocale preference, limited to a table of SpeechTranscriber locales, and read it when a recording starts. Absent keeps today's device-language behavior. --- .../voice-input/VoiceInputProvider.tsx | 7 +++- .../mobile/src/lib/dictationLanguages.test.ts | 19 ++++++++++ apps/mobile/src/lib/dictationLanguages.ts | 38 +++++++++++++++++++ .../src/native/voiceTranscription.ios.test.ts | 16 ++++++++ .../src/native/voiceTranscription.ios.ts | 4 +- apps/mobile/src/native/voiceTranscription.ts | 2 +- .../src/persistence/mobile-preferences.ts | 7 ++++ 7 files changed, 89 insertions(+), 4 deletions(-) create mode 100644 apps/mobile/src/lib/dictationLanguages.test.ts create mode 100644 apps/mobile/src/lib/dictationLanguages.ts diff --git a/apps/mobile/src/features/voice-input/VoiceInputProvider.tsx b/apps/mobile/src/features/voice-input/VoiceInputProvider.tsx index 48f75b4ff32ec..107705c245df6 100644 --- a/apps/mobile/src/features/voice-input/VoiceInputProvider.tsx +++ b/apps/mobile/src/features/voice-input/VoiceInputProvider.tsx @@ -153,7 +153,12 @@ function useVoiceInputRuntime() { recorderRef.current = recorder; sessionRef.current = new VoiceInputSession({ recorder, - getTranscriber: getLocalVoiceTranscriber, + getTranscriber: () => { + const preferences = registry.get(mobilePreferencesAtom); + return getLocalVoiceTranscriber( + AsyncResult.isSuccess(preferences) ? preferences.value.voiceInputLocale : undefined, + ); + }, requestPermission: async () => { const permission = await requestRecordingPermissionsAsync(); return { granted: permission.granted, canAskAgain: permission.canAskAgain }; diff --git a/apps/mobile/src/lib/dictationLanguages.test.ts b/apps/mobile/src/lib/dictationLanguages.test.ts new file mode 100644 index 0000000000000..22c44db3af955 --- /dev/null +++ b/apps/mobile/src/lib/dictationLanguages.test.ts @@ -0,0 +1,19 @@ +import { describe, expect, it } from "vite-plus/test"; + +import { dictationLanguageLabel, isDictationLanguage } from "./dictationLanguages"; + +describe("isDictationLanguage", () => { + it("accepts listed ids and rejects anything else", () => { + expect(isDictationLanguage("pt-BR")).toBe(true); + expect(isDictationLanguage("pt")).toBe(false); + expect(isDictationLanguage("xx-XX")).toBe(false); + expect(isDictationLanguage(42)).toBe(false); + }); +}); + +describe("dictationLanguageLabel", () => { + it("names the chosen language and falls back to the device language", () => { + expect(dictationLanguageLabel("pt-BR")).toBe("Português (Brasil)"); + expect(dictationLanguageLabel(undefined)).toBe("Device language"); + }); +}); diff --git a/apps/mobile/src/lib/dictationLanguages.ts b/apps/mobile/src/lib/dictationLanguages.ts new file mode 100644 index 0000000000000..e1ae6ab8694a4 --- /dev/null +++ b/apps/mobile/src/lib/dictationLanguages.ts @@ -0,0 +1,38 @@ +// Every id is in SpeechTranscriber.supportedLocales on iOS 26. Labels are endonyms written out +// because Hermes's Intl.DisplayNames support is not guaranteed. +export const DICTATION_LANGUAGES: ReadonlyArray<{ readonly id: string; readonly label: string }> = [ + { id: "de-DE", label: "Deutsch (Deutschland)" }, + { id: "en-AU", label: "English (Australia)" }, + { id: "en-CA", label: "English (Canada)" }, + { id: "en-IN", label: "English (India)" }, + { id: "en-GB", label: "English (UK)" }, + { id: "en-US", label: "English (US)" }, + { id: "es-ES", label: "Español (España)" }, + { id: "es-US", label: "Español (Estados Unidos)" }, + { id: "es-MX", label: "Español (México)" }, + { id: "fr-CA", label: "Français (Canada)" }, + { id: "fr-FR", label: "Français (France)" }, + { id: "it-IT", label: "Italiano (Italia)" }, + { id: "pt-BR", label: "Português (Brasil)" }, + { id: "pt-PT", label: "Português (Portugal)" }, + { id: "hi-IN", label: "हिन्दी (भारत)" }, + { id: "ko-KR", label: "한국어(대한민국)" }, + { id: "zh-CN", label: "中文(中国大陆)" }, + { id: "zh-HK", label: "中文(香港)" }, + { id: "zh-TW", label: "中文(台灣)" }, + { id: "ja-JP", label: "日本語 (日本)" }, + { id: "yue-CN", label: "粤语(中国大陆)" }, +]; + +export const DEVICE_DICTATION_LANGUAGE_LABEL = "Device language"; + +export function isDictationLanguage(value: unknown): value is string { + return DICTATION_LANGUAGES.some((language) => language.id === value); +} + +export function dictationLanguageLabel(id: string | undefined): string { + return ( + DICTATION_LANGUAGES.find((language) => language.id === id)?.label ?? + DEVICE_DICTATION_LANGUAGE_LABEL + ); +} diff --git a/apps/mobile/src/native/voiceTranscription.ios.test.ts b/apps/mobile/src/native/voiceTranscription.ios.test.ts index b08e32cdb6f65..79351c9c07bbf 100644 --- a/apps/mobile/src/native/voiceTranscription.ios.test.ts +++ b/apps/mobile/src/native/voiceTranscription.ios.test.ts @@ -74,6 +74,22 @@ describe("getLocalVoiceTranscriber", () => { expect(mocks.transcribe).toHaveBeenCalledWith(audio, "sv-SE"); }); + it("prepares the chosen dictation language instead of the device language", async () => { + const resolvedOptions = Intl.DateTimeFormat().resolvedOptions(); + vi.spyOn(Intl.DateTimeFormat.prototype, "resolvedOptions").mockReturnValue({ + ...resolvedOptions, + locale: "en-US", + }); + mocks.prepare.mockResolvedValue("pt_BR"); + + const prepared = await getLocalVoiceTranscriber("pt-BR")!.prepare({ + signal: new AbortController().signal, + }); + + expect(mocks.prepare).toHaveBeenCalledWith("pt-BR"); + expect(prepared.locale).toBe("pt_BR"); + }); + it("does not start native transcription after cancellation during a file read", async () => { const enteredRead = deferred(); const readResult = deferred(); diff --git a/apps/mobile/src/native/voiceTranscription.ios.ts b/apps/mobile/src/native/voiceTranscription.ios.ts index 216b9e958dd66..d0741284787a2 100644 --- a/apps/mobile/src/native/voiceTranscription.ios.ts +++ b/apps/mobile/src/native/voiceTranscription.ios.ts @@ -33,8 +33,8 @@ function getNativeErrorCode(error: unknown): string | undefined { return typeof error.code === "string" ? error.code : undefined; } -export function getLocalVoiceTranscriber(): VoiceTranscriber | null { - const locale = getDeviceLocale(); +export function getLocalVoiceTranscriber(preferredLocale?: string): VoiceTranscriber | null { + const locale = preferredLocale ?? getDeviceLocale(); if (!AppleTranscription.isAvailable(locale)) return null; return { prepare: (options) => prepareVoiceTranscription(locale, options) }; } diff --git a/apps/mobile/src/native/voiceTranscription.ts b/apps/mobile/src/native/voiceTranscription.ts index e003064ae3f84..8008a2d9ac522 100644 --- a/apps/mobile/src/native/voiceTranscription.ts +++ b/apps/mobile/src/native/voiceTranscription.ts @@ -1,5 +1,5 @@ import type { VoiceTranscriber } from "@t3tools/client-runtime/voice-input"; -export function getLocalVoiceTranscriber(): VoiceTranscriber | null { +export function getLocalVoiceTranscriber(_preferredLocale?: string): VoiceTranscriber | null { return null; } diff --git a/apps/mobile/src/persistence/mobile-preferences.ts b/apps/mobile/src/persistence/mobile-preferences.ts index 7acdd47e4e667..d620d0fa9447b 100644 --- a/apps/mobile/src/persistence/mobile-preferences.ts +++ b/apps/mobile/src/persistence/mobile-preferences.ts @@ -16,6 +16,7 @@ import { } from "@t3tools/contracts"; import type { ComposerEnterBehavior } from "../lib/composerEnterBehavior"; import type { FollowUpBehavior } from "../lib/followUpBehavior"; +import { isDictationLanguage } from "../lib/dictationLanguages"; import { isMicrophoneKind, type MicrophoneEntry } from "../lib/microphonePriority"; import { MOBILE_THEME_IDS, type MobileThemeId, type MobileThemeMode } from "../lib/mobileTheme"; import * as MobileDatabase from "./mobile-database"; @@ -72,6 +73,8 @@ export interface Preferences { readonly composerEnterBehavior?: ComposerEnterBehavior; readonly followUpBehavior?: FollowUpBehavior; readonly microphones?: ReadonlyArray; + /** An id from `DICTATION_LANGUAGES`. Writing undefined returns to the device language. */ + readonly voiceInputLocale?: string | undefined; readonly projectGroupingEnabled?: boolean; readonly projectGroupingMode?: SidebarProjectGroupingMode; readonly planModeEnabled?: boolean; @@ -145,6 +148,7 @@ function sanitizePreferences(parsed: Preferences): Preferences { composerEnterBehavior?: ComposerEnterBehavior; followUpBehavior?: FollowUpBehavior; microphones?: ReadonlyArray; + voiceInputLocale?: string; projectGroupingEnabled?: boolean; projectGroupingMode?: SidebarProjectGroupingMode; planModeEnabled?: boolean; @@ -240,6 +244,9 @@ function sanitizePreferences(parsed: Preferences): Preferences { : []; }); } + if (isDictationLanguage(parsed.voiceInputLocale)) { + preferences.voiceInputLocale = parsed.voiceInputLocale; + } if (typeof parsed.projectGroupingEnabled === "boolean") { preferences.projectGroupingEnabled = parsed.projectGroupingEnabled; } From c78c6a29e4b9c836ee4d5664f77a9e784fa691cd Mon Sep 17 00:00:00 2001 From: Gabriel Taveira Date: Tue, 20 Oct 2026 12:13:37 -0300 Subject: [PATCH 2/6] feat(mobile): pick the dictation language in Settings Settings > Microphone gets a Language section whose row opens a picker: Device language first, then the supported languages. --- apps/mobile/src/Stack.tsx | 8 ++++ .../SettingsDictationLanguageRouteScreen.tsx | 47 +++++++++++++++++++ .../SettingsMicrophoneRouteScreen.tsx | 14 ++++++ .../components/settings-sheet-targets.ts | 1 + docs/user/composer.md | 3 ++ 5 files changed, 73 insertions(+) create mode 100644 apps/mobile/src/features/settings/SettingsDictationLanguageRouteScreen.tsx diff --git a/apps/mobile/src/Stack.tsx b/apps/mobile/src/Stack.tsx index 16abe358e911d..588c074a58be5 100644 --- a/apps/mobile/src/Stack.tsx +++ b/apps/mobile/src/Stack.tsx @@ -100,6 +100,7 @@ import { SettingsProviderAccountsRouteScreen } from "./features/settings/Setting import { SettingsAuthRouteScreen } from "./features/settings/SettingsAuthRouteScreen"; import { SettingsEnvironmentDetailRouteScreen } from "./features/settings/SettingsEnvironmentDetailRouteScreen"; import { SettingsEnvironmentsRouteScreen } from "./features/settings/SettingsEnvironmentsRouteScreen"; +import { SettingsDictationLanguageRouteScreen } from "./features/settings/SettingsDictationLanguageRouteScreen"; import { SettingsFollowUpRouteScreen } from "./features/settings/SettingsFollowUpRouteScreen"; import { SettingsEnvironmentAgentBehaviorRouteScreen, @@ -332,6 +333,13 @@ const SettingsContentStack = createV5SheetStackNavigator({ title: "Microphone", }, }), + SettingsDictationLanguage: createNativeStackScreen({ + screen: SettingsDictationLanguageRouteScreen, + linking: "dictation-language", + options: { + title: "Dictation language", + }, + }), SettingsFollowUp: createNativeStackScreen({ screen: SettingsFollowUpRouteScreen, linking: "follow-ups", diff --git a/apps/mobile/src/features/settings/SettingsDictationLanguageRouteScreen.tsx b/apps/mobile/src/features/settings/SettingsDictationLanguageRouteScreen.tsx new file mode 100644 index 0000000000000..7de058ff0df01 --- /dev/null +++ b/apps/mobile/src/features/settings/SettingsDictationLanguageRouteScreen.tsx @@ -0,0 +1,47 @@ +import { ScreenScrollView as ScrollView } from "../../components/ui/ScreenScrollView"; +import { useAtomSet, useAtomValue } from "@effect/atom-react"; +import { AsyncResult } from "effect/reactivity"; +import { View } from "react-native"; +import { useSafeAreaInsets } from "react-native-safe-area-context"; + +import { DEVICE_DICTATION_LANGUAGE_LABEL, DICTATION_LANGUAGES } from "../../lib/dictationLanguages"; +import { mobilePreferencesAtom, updateMobilePreferencesAtom } from "../../state/preferences"; +import { SettingsChoiceRow } from "./components/SettingsChoiceRow"; +import { SettingsSection } from "./components/SettingsSection"; + +const OPTIONS = [{ id: undefined, label: DEVICE_DICTATION_LANGUAGE_LABEL }, ...DICTATION_LANGUAGES]; + +export function SettingsDictationLanguageRouteScreen() { + const insets = useSafeAreaInsets(); + const preferencesResult = useAtomValue(mobilePreferencesAtom); + const savePreferences = useAtomSet(updateMobilePreferencesAtom); + const preferencesReady = AsyncResult.isSuccess(preferencesResult) && !preferencesResult.waiting; + const selectedId = AsyncResult.isSuccess(preferencesResult) + ? preferencesResult.value.voiceInputLocale + : null; + + return ( + + + + {OPTIONS.map((option, index) => ( + 0} + disabled={!preferencesReady} + onPress={() => savePreferences({ voiceInputLocale: option.id })} + /> + ))} + + + + ); +} diff --git a/apps/mobile/src/features/settings/SettingsMicrophoneRouteScreen.tsx b/apps/mobile/src/features/settings/SettingsMicrophoneRouteScreen.tsx index 77154bb071d89..b1532fff95871 100644 --- a/apps/mobile/src/features/settings/SettingsMicrophoneRouteScreen.tsx +++ b/apps/mobile/src/features/settings/SettingsMicrophoneRouteScreen.tsx @@ -11,6 +11,7 @@ import { useSafeAreaInsets } from "react-native-safe-area-context"; import { type AppSymbolName, SymbolView } from "../../components/ui/AppSymbol"; import { AppText as Text } from "../../components/ui/AppText"; import { cn } from "../../lib/cn"; +import { dictationLanguageLabel } from "../../lib/dictationLanguages"; import { isMicrophoneDevice, type MicrophoneEntry, @@ -21,6 +22,7 @@ import { import { mobilePreferencesAtom, updateMobilePreferencesAtom } from "../../state/preferences"; import { SettingsActionRow } from "./components/SettingsActionRow"; import { SettingsDragHandle } from "./components/SettingsDragHandle"; +import { SettingsRow } from "./components/SettingsRow"; import { SettingsSection } from "./components/SettingsSection"; const REMOVE_SIZE = 20; @@ -214,6 +216,18 @@ export function SettingsMicrophoneRouteScreen() { devices are added by name after you use voice input with them connected; until then, the Other row ranks them. + + + ); diff --git a/apps/mobile/src/features/settings/components/settings-sheet-targets.ts b/apps/mobile/src/features/settings/components/settings-sheet-targets.ts index 611a1b3410c73..6790df5692acf 100644 --- a/apps/mobile/src/features/settings/components/settings-sheet-targets.ts +++ b/apps/mobile/src/features/settings/components/settings-sheet-targets.ts @@ -14,6 +14,7 @@ export type SettingsSheetTarget = | "SettingsProviderAccounts" | "SettingsKeyboard" | "SettingsMicrophone" + | "SettingsDictationLanguage" | "SettingsFollowUp" | "SettingsScheduledTasks" | "SettingsProjectGrouping" diff --git a/docs/user/composer.md b/docs/user/composer.md index a784b625108c0..6355f67ac4b66 100644 --- a/docs/user/composer.md +++ b/docs/user/composer.md @@ -192,6 +192,9 @@ for example, put **Other Bluetooth** above your AirPods so a new headset is pref while the AirPods microphone stays low. By default, CarPlay comes after the built-in microphone. +Voice input transcribes in your iPhone's language. If you speak a different language, +pick it in **Settings → Microphone → Dictation language**. + Transcription runs on your device. T3 Code deletes the temporary audio after transcription or cancellation; only the message text is sent when you submit. From c972b1370405ee0c5205c85c6a65095deb2df237 Mon Sep 17 00:00:00 2001 From: Gabriel Taveira Date: Tue, 20 Oct 2026 12:32:01 -0300 Subject: [PATCH 3/6] fix(mobile): keep Device language after other preference saves Picking Device language wrote voiceInputLocale: undefined, which JSON drops. The preferences atom merges the initial load under confirmed saves, so the next unrelated save brought the old locale back. Store null for the device language, matching terminalFontSize and codeFontSize. --- .../SettingsDictationLanguageRouteScreen.tsx | 6 +- .../voice-input/VoiceInputProvider.tsx | 4 +- apps/mobile/src/lib/dictationLanguages.ts | 2 +- .../src/persistence/mobile-preferences.ts | 8 +- apps/mobile/src/state/preferences.test.ts | 80 +++++++++++++++++++ 5 files changed, 91 insertions(+), 9 deletions(-) diff --git a/apps/mobile/src/features/settings/SettingsDictationLanguageRouteScreen.tsx b/apps/mobile/src/features/settings/SettingsDictationLanguageRouteScreen.tsx index 7de058ff0df01..531944160e18e 100644 --- a/apps/mobile/src/features/settings/SettingsDictationLanguageRouteScreen.tsx +++ b/apps/mobile/src/features/settings/SettingsDictationLanguageRouteScreen.tsx @@ -9,7 +9,7 @@ import { mobilePreferencesAtom, updateMobilePreferencesAtom } from "../../state/ import { SettingsChoiceRow } from "./components/SettingsChoiceRow"; import { SettingsSection } from "./components/SettingsSection"; -const OPTIONS = [{ id: undefined, label: DEVICE_DICTATION_LANGUAGE_LABEL }, ...DICTATION_LANGUAGES]; +const OPTIONS = [{ id: null, label: DEVICE_DICTATION_LANGUAGE_LABEL }, ...DICTATION_LANGUAGES]; export function SettingsDictationLanguageRouteScreen() { const insets = useSafeAreaInsets(); @@ -17,8 +17,8 @@ export function SettingsDictationLanguageRouteScreen() { const savePreferences = useAtomSet(updateMobilePreferencesAtom); const preferencesReady = AsyncResult.isSuccess(preferencesResult) && !preferencesResult.waiting; const selectedId = AsyncResult.isSuccess(preferencesResult) - ? preferencesResult.value.voiceInputLocale - : null; + ? (preferencesResult.value.voiceInputLocale ?? null) + : undefined; return ( diff --git a/apps/mobile/src/features/voice-input/VoiceInputProvider.tsx b/apps/mobile/src/features/voice-input/VoiceInputProvider.tsx index 107705c245df6..932408671bd2a 100644 --- a/apps/mobile/src/features/voice-input/VoiceInputProvider.tsx +++ b/apps/mobile/src/features/voice-input/VoiceInputProvider.tsx @@ -156,7 +156,9 @@ function useVoiceInputRuntime() { getTranscriber: () => { const preferences = registry.get(mobilePreferencesAtom); return getLocalVoiceTranscriber( - AsyncResult.isSuccess(preferences) ? preferences.value.voiceInputLocale : undefined, + AsyncResult.isSuccess(preferences) + ? (preferences.value.voiceInputLocale ?? undefined) + : undefined, ); }, requestPermission: async () => { diff --git a/apps/mobile/src/lib/dictationLanguages.ts b/apps/mobile/src/lib/dictationLanguages.ts index e1ae6ab8694a4..7a1bb57bfd7ce 100644 --- a/apps/mobile/src/lib/dictationLanguages.ts +++ b/apps/mobile/src/lib/dictationLanguages.ts @@ -30,7 +30,7 @@ export function isDictationLanguage(value: unknown): value is string { return DICTATION_LANGUAGES.some((language) => language.id === value); } -export function dictationLanguageLabel(id: string | undefined): string { +export function dictationLanguageLabel(id: string | null | undefined): string { return ( DICTATION_LANGUAGES.find((language) => language.id === id)?.label ?? DEVICE_DICTATION_LANGUAGE_LABEL diff --git a/apps/mobile/src/persistence/mobile-preferences.ts b/apps/mobile/src/persistence/mobile-preferences.ts index d620d0fa9447b..ea8b3bec84a89 100644 --- a/apps/mobile/src/persistence/mobile-preferences.ts +++ b/apps/mobile/src/persistence/mobile-preferences.ts @@ -73,8 +73,8 @@ export interface Preferences { readonly composerEnterBehavior?: ComposerEnterBehavior; readonly followUpBehavior?: FollowUpBehavior; readonly microphones?: ReadonlyArray; - /** An id from `DICTATION_LANGUAGES`. Writing undefined returns to the device language. */ - readonly voiceInputLocale?: string | undefined; + /** An id from `DICTATION_LANGUAGES`, or null for the device language. */ + readonly voiceInputLocale?: string | null; readonly projectGroupingEnabled?: boolean; readonly projectGroupingMode?: SidebarProjectGroupingMode; readonly planModeEnabled?: boolean; @@ -148,7 +148,7 @@ function sanitizePreferences(parsed: Preferences): Preferences { composerEnterBehavior?: ComposerEnterBehavior; followUpBehavior?: FollowUpBehavior; microphones?: ReadonlyArray; - voiceInputLocale?: string; + voiceInputLocale?: string | null; projectGroupingEnabled?: boolean; projectGroupingMode?: SidebarProjectGroupingMode; planModeEnabled?: boolean; @@ -244,7 +244,7 @@ function sanitizePreferences(parsed: Preferences): Preferences { : []; }); } - if (isDictationLanguage(parsed.voiceInputLocale)) { + if (isDictationLanguage(parsed.voiceInputLocale) || parsed.voiceInputLocale === null) { preferences.voiceInputLocale = parsed.voiceInputLocale; } if (typeof parsed.projectGroupingEnabled === "boolean") { diff --git a/apps/mobile/src/state/preferences.test.ts b/apps/mobile/src/state/preferences.test.ts index 852913943ac23..ce112588b8d25 100644 --- a/apps/mobile/src/state/preferences.test.ts +++ b/apps/mobile/src/state/preferences.test.ts @@ -27,7 +27,9 @@ vi.mock("../lib/runtime", async () => { }); import { createMobilePreferencesState } from "./preferences"; +import * as MobileDatabase from "../persistence/mobile-database"; import * as MobilePreferences from "../persistence/mobile-preferences"; +import * as MobileSecureStorage from "../persistence/mobile-secure-storage"; function deferred() { let resolve!: (value: A) => void; @@ -60,6 +62,53 @@ function makePreferencesState( ); } +function makePreferencesStore(initialPayload: MobilePreferences.Preferences) { + const row = { payload: JSON.stringify(initialPayload), updatedAt: 1 }; + const unused = Effect.die("unused in preferences tests"); + return MobilePreferences.make().pipe( + Effect.provideService( + MobileDatabase.MobileDatabase, + MobileDatabase.MobileDatabase.of({ + loadCache: () => unused, + listCache: () => unused, + saveCache: () => unused, + removeCache: () => unused, + clearCacheKind: () => unused, + clearEnvironmentCache: () => unused, + clearAllCaches: unused, + inspectCaches: unused, + loadPreferencesJson: Effect.sync(() => Option.some({ ...row })), + savePreferencesJson: (payload, updatedAt) => + Effect.sync(() => { + row.payload = payload; + row.updatedAt = updatedAt; + }), + }), + ), + Effect.provideService( + MobileSecureStorage.MobileSecureStorage, + MobileSecureStorage.MobileSecureStorage.of({ + getItem: () => Effect.succeed(null), + setItem: () => Effect.void, + removeItem: () => Effect.void, + }), + ), + Effect.map((store) => ({ store, storedPayload: () => JSON.parse(row.payload) as unknown })), + ); +} + +describe("mobile preferences store", () => { + it.effect("keeps a null dictation language and drops an unknown one", () => + Effect.gen(function* () { + const cleared = yield* makePreferencesStore({ voiceInputLocale: null }); + expect(yield* cleared.store.load).toEqual({ voiceInputLocale: null }); + + const unknown = yield* makePreferencesStore({ voiceInputLocale: "xx-XX" }); + expect(yield* unknown.store.load).toEqual({}); + }), + ); +}); + describe("mobile preferences state", () => { it.effect("shares one preference load across consumers", () => Effect.gen(function* () { @@ -355,4 +404,35 @@ describe("mobile preferences state", () => { registry.dispose(); }), ); + + it.effect("keeps the device dictation language after another preference saves", () => + Effect.gen(function* () { + const { store, storedPayload } = yield* makePreferencesStore({ voiceInputLocale: "pt-BR" }); + const state = createMobilePreferencesState( + Atom.runtime(Layer.succeed(MobilePreferences.MobilePreferencesStore, store)), + ); + const registry = AtomRegistry.make(); + const unmountPreferences = registry.mount(state.preferencesAtom); + const unmountUpdate = registry.mount(state.updatePreferencesAtom); + const save = (patch: Partial) => { + registry.set(state.updatePreferencesAtom, patch); + return AtomRegistry.getResult(registry, state.updatePreferencesAtom, { + suspendOnWaiting: true, + }); + }; + + yield* AtomRegistry.getResult(registry, state.preferencesAtom, { suspendOnWaiting: true }); + yield* save({ voiceInputLocale: null }); + yield* save({ baseFontSize: 18 }); + + expect( + yield* AtomRegistry.getResult(registry, state.preferencesAtom, { suspendOnWaiting: true }), + ).toEqual({ voiceInputLocale: null, baseFontSize: 18 }); + expect(storedPayload()).toEqual({ voiceInputLocale: null, baseFontSize: 18 }); + + unmountUpdate(); + unmountPreferences(); + registry.dispose(); + }), + ); }); From 40b20407274c97b730cdb4e63b185fac5a073e67 Mon Sep 17 00:00:00 2001 From: Gabriel Taveira Date: Tue, 20 Oct 2026 12:57:22 -0300 Subject: [PATCH 4/6] feat(mobile): native transcription module lists the languages the device supports --- patches/@react-native-ai__apple@0.12.0.patch | 66 +++++++++++++++++--- pnpm-lock.yaml | 6 +- 2 files changed, 62 insertions(+), 10 deletions(-) diff --git a/patches/@react-native-ai__apple@0.12.0.patch b/patches/@react-native-ai__apple@0.12.0.patch index b2a7aaf229914..6b5890d8095e1 100644 --- a/patches/@react-native-ai__apple@0.12.0.patch +++ b/patches/@react-native-ai__apple@0.12.0.patch @@ -1,5 +1,18 @@ +diff --git a/ios/transcription/AppleTranscription.mm b/ios/transcription/AppleTranscription.mm +index c0f036ce7d9905cf7a54c80199e4d6039f64ef30..fac31400a57098527637161cde70fbbd92b5652e 100644 +--- a/ios/transcription/AppleTranscription.mm ++++ b/ios/transcription/AppleTranscription.mm +@@ -116,4 +116,8 @@ - (void)prepare:(nonnull NSString *)language resolve:(nonnull RCTPromiseResolveB + [_transcription prepare:language resolve:resolve reject:reject]; + } + ++- (void)supportedLanguages:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject { ++ [_transcription supportedLanguages:resolve]; ++} ++ + @end diff --git a/ios/transcription/AppleTranscriptionImpl.swift b/ios/transcription/AppleTranscriptionImpl.swift -index 188371a5f55fadae19187108c4a688569d0223e3..3e1cdd77b0bb8ae6c97a40d29c1854200d931eee 100644 +index 188371a5f55fadae19187108c4a688569d0223e3..0baaed8196491d2791f97fd6b861163f1ff10491 100644 --- a/ios/transcription/AppleTranscriptionImpl.swift +++ b/ios/transcription/AppleTranscriptionImpl.swift @@ -12,6 +12,11 @@ import UniformTypeIdentifiers @@ -44,7 +57,30 @@ index 188371a5f55fadae19187108c4a688569d0223e3..3e1cdd77b0bb8ae6c97a40d29c185420 @unknown default: reject ("AppleTranscription", "Unknown asset inventory status", nil) } -@@ -83,57 +86,77 @@ public class AppleTranscriptionImpl: NSObject { +@@ -73,6 +76,22 @@ public class AppleTranscriptionImpl: NSObject { + } + } + ++ @objc ++ public func supportedLanguages(_ resolve: @escaping (Any?) -> Void) { ++ guard #available(iOS 26, *) else { ++ resolve([]) ++ return ++ } ++ Task { ++ let languages = await SpeechTranscriber.supportedLocales.map { locale -> [String: String] in ++ let id = locale.identifier(.bcp47) ++ let name = locale.localizedString(forIdentifier: locale.identifier) ?? id ++ return ["id": id, "label": name.prefix(1).uppercased(with: locale) + name.dropFirst()] ++ } ++ resolve(languages) ++ } ++ } ++ + @objc + public func transcribe(_ audioData: Data, language: String, resolve: @escaping ([String: Any]) -> Void, reject: @escaping (String, String, Error?) -> Void) { + if #available(iOS 26, *) { +@@ -83,57 +102,77 @@ public class AppleTranscriptionImpl: NSObject { do { try audioData.write(to: fileURL) @@ -153,21 +189,25 @@ index 188371a5f55fadae19187108c4a688569d0223e3..3e1cdd77b0bb8ae6c97a40d29c185420 reject("AppleTranscription", "Failed to write audio data: \(error.localizedDescription)", error) } } else { -@@ -141,4 +164,3 @@ public class AppleTranscriptionImpl: NSObject { +@@ -141,4 +180,3 @@ public class AppleTranscriptionImpl: NSObject { } } } - diff --git a/lib/typescript/NativeAppleTranscription.d.ts b/lib/typescript/NativeAppleTranscription.d.ts -index 985b6b3593a884c41d689346be9d73d86c55eae1..86e7936f23a8673d099f7fe18af9a31abae5a13a 100644 +index 985b6b3593a884c41d689346be9d73d86c55eae1..e030c91e6b1b6bb856c92aa9144434c775734852 100644 --- a/lib/typescript/NativeAppleTranscription.d.ts +++ b/lib/typescript/NativeAppleTranscription.d.ts -@@ -10,14 +10,14 @@ export interface TranscriptionResult { +@@ -10,14 +10,22 @@ export interface TranscriptionResult { } export interface Spec extends TurboModule { isAvailable(language: string): boolean; - prepare(language: string): Promise; + prepare(language: string): Promise; ++ supportedLanguages(): Promise>; } declare global { function __apple__llm__transcribe__(data: ArrayBufferLike, language: string): Promise; @@ -176,19 +216,31 @@ index 985b6b3593a884c41d689346be9d73d86c55eae1..86e7936f23a8673d099f7fe18af9a31a transcribe: (data: ArrayBufferLike, language: string) => Promise; - prepare: (language: string) => Promise; + prepare: (language: string) => Promise; ++ supportedLanguages: () => Promise>; isAvailable: (language: string) => boolean; }; export default _default; diff --git a/src/NativeAppleTranscription.ts b/src/NativeAppleTranscription.ts -index 13332a0176000b60b6f6f043de681db55a7b4bef..5389fb4b3a53de48721c307d2145b6770624c852 100644 +index 13332a0176000b60b6f6f043de681db55a7b4bef..8bb7b281b3f03dedfa3758f4d4354a7d2af72b85 100644 --- a/src/NativeAppleTranscription.ts +++ b/src/NativeAppleTranscription.ts -@@ -14,7 +14,7 @@ export interface TranscriptionResult { +@@ -14,7 +14,8 @@ export interface TranscriptionResult { export interface Spec extends TurboModule { isAvailable(language: string): boolean - prepare(language: string): Promise + prepare(language: string): Promise ++ supportedLanguages(): Promise> } declare global { +@@ -32,5 +33,6 @@ export default { + transcribe: (data: ArrayBufferLike, language: string) => + globalThis.__apple__llm__transcribe__(data, language), + prepare: NativeAppleTranscription.prepare, ++ supportedLanguages: NativeAppleTranscription.supportedLanguages, + isAvailable: NativeAppleTranscription.isAvailable, + } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a202831a6fb00..7fc99a5f82d96 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -174,7 +174,7 @@ patchedDependencies: '@ff-labs/fff-node@0.11.0': cc71fcec015f4d39bc96ae2e2bf6b0ca678124c722c66a7841efce9d34b5983c '@legendapp/list@3.3.5': e6383c516a0d67b65333d6fd38d2203734bf24b054b0b0767b034189205aed32 '@pierre/diffs@1.5.2': 2ec81ba1e8ce4681095a3473c2bf78e630417740c622720ef624febb467c25fc - '@react-native-ai/apple@0.12.0': 2d09870c2848d185cb05b53ed823a46e12dba519324d8dd8e584e28731990f9d + '@react-native-ai/apple@0.12.0': 268fa178f07af686634ad9963eaee6ed1e5ca800ce7fd16300df87c007562838 '@react-native-menu/menu@2.0.0': a4866ecfcd44f318043de839d20110c17e14909004900f002ffe12050376f2ba '@react-navigation/native-stack@7.21.0': caae6552051bce91a85f567f3a08f9c8d25ce4c53f65a9391a67f016bb1d798e alchemy@2.0.0-beta.80: bea1b6c0c0b23157fd5f439a1d7feff430f28ac1621ba135d8a13eeec60ccacd @@ -364,7 +364,7 @@ importers: version: 1.5.2(patch_hash=2ec81ba1e8ce4681095a3473c2bf78e630417740c622720ef624febb467c25fc)(@shikijs/themes@4.2.0)(react-dom@19.3.0(react@19.3.0))(react@19.3.0) '@react-native-ai/apple': specifier: 0.12.0 - version: 0.12.0(patch_hash=2d09870c2848d185cb05b53ed823a46e12dba519324d8dd8e584e28731990f9d)(react-native@0.88.0(@babel/core@7.29.7)(@react-native/metro-config@0.88.0(@babel/core@7.29.7)(bufferutil@4.1.0)(utf-8-validate@6.0.6))(@types/react@19.3.0)(bufferutil@4.1.0)(react@19.3.0)(utf-8-validate@6.0.6)) + version: 0.12.0(patch_hash=268fa178f07af686634ad9963eaee6ed1e5ca800ce7fd16300df87c007562838)(react-native@0.88.0(@babel/core@7.29.7)(@react-native/metro-config@0.88.0(@babel/core@7.29.7)(bufferutil@4.1.0)(utf-8-validate@6.0.6))(@types/react@19.3.0)(bufferutil@4.1.0)(react@19.3.0)(utf-8-validate@6.0.6)) '@react-native-async-storage/async-storage': specifier: 3.1.1 version: 3.1.1(react-native@0.88.0(@babel/core@7.29.7)(@react-native/metro-config@0.88.0(@babel/core@7.29.7)(bufferutil@4.1.0)(utf-8-validate@6.0.6))(@types/react@19.3.0)(bufferutil@4.1.0)(react@19.3.0)(utf-8-validate@6.0.6))(react@19.3.0) @@ -16289,7 +16289,7 @@ snapshots: prompts: 2.4.2 tinyexec: 1.2.4 - '@react-native-ai/apple@0.12.0(patch_hash=2d09870c2848d185cb05b53ed823a46e12dba519324d8dd8e584e28731990f9d)(react-native@0.88.0(@babel/core@7.29.7)(@react-native/metro-config@0.88.0(@babel/core@7.29.7)(bufferutil@4.1.0)(utf-8-validate@6.0.6))(@types/react@19.3.0)(bufferutil@4.1.0)(react@19.3.0)(utf-8-validate@6.0.6))': + '@react-native-ai/apple@0.12.0(patch_hash=268fa178f07af686634ad9963eaee6ed1e5ca800ce7fd16300df87c007562838)(react-native@0.88.0(@babel/core@7.29.7)(@react-native/metro-config@0.88.0(@babel/core@7.29.7)(bufferutil@4.1.0)(utf-8-validate@6.0.6))(@types/react@19.3.0)(bufferutil@4.1.0)(react@19.3.0)(utf-8-validate@6.0.6))': dependencies: '@ai-sdk/provider': 3.0.15 '@ai-sdk/provider-utils': 4.0.57(zod@4.4.3) From 7b354f982233b3dfd352317a4297f21ef4f54b31 Mon Sep 17 00:00:00 2001 From: Gabriel Taveira Date: Tue, 20 Oct 2026 12:57:22 -0300 Subject: [PATCH 5/6] feat(mobile): dictation language picker lists what the device supports --- .../SettingsDictationLanguageRouteScreen.tsx | 19 ++++-- .../SettingsMicrophoneRouteScreen.tsx | 4 +- .../mobile/src/lib/dictationLanguages.test.ts | 26 ++++---- apps/mobile/src/lib/dictationLanguages.ts | 60 +++++++++---------- .../src/native/voiceTranscription.ios.test.ts | 27 ++++++++- .../src/native/voiceTranscription.ios.ts | 7 +++ apps/mobile/src/native/voiceTranscription.ts | 6 ++ .../src/native/voiceTranscription.types.ts | 4 ++ .../src/persistence/mobile-preferences.ts | 12 +++- apps/mobile/src/state/preferences.test.ts | 9 ++- 10 files changed, 117 insertions(+), 57 deletions(-) create mode 100644 apps/mobile/src/native/voiceTranscription.types.ts diff --git a/apps/mobile/src/features/settings/SettingsDictationLanguageRouteScreen.tsx b/apps/mobile/src/features/settings/SettingsDictationLanguageRouteScreen.tsx index 531944160e18e..b350ba64a1176 100644 --- a/apps/mobile/src/features/settings/SettingsDictationLanguageRouteScreen.tsx +++ b/apps/mobile/src/features/settings/SettingsDictationLanguageRouteScreen.tsx @@ -4,13 +4,14 @@ import { AsyncResult } from "effect/reactivity"; import { View } from "react-native"; import { useSafeAreaInsets } from "react-native-safe-area-context"; -import { DEVICE_DICTATION_LANGUAGE_LABEL, DICTATION_LANGUAGES } from "../../lib/dictationLanguages"; +import { + DEVICE_DICTATION_LANGUAGE_LABEL, + useDictationLanguages, +} from "../../lib/dictationLanguages"; import { mobilePreferencesAtom, updateMobilePreferencesAtom } from "../../state/preferences"; import { SettingsChoiceRow } from "./components/SettingsChoiceRow"; import { SettingsSection } from "./components/SettingsSection"; -const OPTIONS = [{ id: null, label: DEVICE_DICTATION_LANGUAGE_LABEL }, ...DICTATION_LANGUAGES]; - export function SettingsDictationLanguageRouteScreen() { const insets = useSafeAreaInsets(); const preferencesResult = useAtomValue(mobilePreferencesAtom); @@ -19,6 +20,8 @@ export function SettingsDictationLanguageRouteScreen() { const selectedId = AsyncResult.isSuccess(preferencesResult) ? (preferencesResult.value.voiceInputLocale ?? null) : undefined; + const languages = useDictationLanguages(); + const options = [{ id: null, label: DEVICE_DICTATION_LANGUAGE_LABEL }, ...(languages ?? [])]; return ( @@ -29,8 +32,14 @@ export function SettingsDictationLanguageRouteScreen() { contentContainerClassName="gap-3 px-5 pt-4" contentContainerStyle={{ paddingBottom: Math.max(insets.bottom, 18) + 18 }} > - - {OPTIONS.map((option, index) => ( + + {options.map((option, index) => ( { - it("accepts listed ids and rejects anything else", () => { - expect(isDictationLanguage("pt-BR")).toBe(true); - expect(isDictationLanguage("pt")).toBe(false); - expect(isDictationLanguage("xx-XX")).toBe(false); - expect(isDictationLanguage(42)).toBe(false); - }); -}); +const languages = [{ id: "pt-BR", label: "Português (Brasil)" }]; describe("dictationLanguageLabel", () => { - it("names the chosen language and falls back to the device language", () => { - expect(dictationLanguageLabel("pt-BR")).toBe("Português (Brasil)"); - expect(dictationLanguageLabel(undefined)).toBe("Device language"); + it("names the chosen language from the loaded list", () => { + expect(dictationLanguageLabel(languages, "pt-BR")).toBe("Português (Brasil)"); + }); + + it("shows the raw tag until the list loads or when the list lacks it", () => { + expect(dictationLanguageLabel(undefined, "pt-BR")).toBe("pt-BR"); + expect(dictationLanguageLabel(languages, "sv-SE")).toBe("sv-SE"); + }); + + it("names the device language when nothing is chosen", () => { + expect(dictationLanguageLabel(languages, null)).toBe("Device language"); + expect(dictationLanguageLabel(undefined, undefined)).toBe("Device language"); }); }); diff --git a/apps/mobile/src/lib/dictationLanguages.ts b/apps/mobile/src/lib/dictationLanguages.ts index 7a1bb57bfd7ce..89b670778b3ca 100644 --- a/apps/mobile/src/lib/dictationLanguages.ts +++ b/apps/mobile/src/lib/dictationLanguages.ts @@ -1,38 +1,34 @@ -// Every id is in SpeechTranscriber.supportedLocales on iOS 26. Labels are endonyms written out -// because Hermes's Intl.DisplayNames support is not guaranteed. -export const DICTATION_LANGUAGES: ReadonlyArray<{ readonly id: string; readonly label: string }> = [ - { id: "de-DE", label: "Deutsch (Deutschland)" }, - { id: "en-AU", label: "English (Australia)" }, - { id: "en-CA", label: "English (Canada)" }, - { id: "en-IN", label: "English (India)" }, - { id: "en-GB", label: "English (UK)" }, - { id: "en-US", label: "English (US)" }, - { id: "es-ES", label: "Español (España)" }, - { id: "es-US", label: "Español (Estados Unidos)" }, - { id: "es-MX", label: "Español (México)" }, - { id: "fr-CA", label: "Français (Canada)" }, - { id: "fr-FR", label: "Français (France)" }, - { id: "it-IT", label: "Italiano (Italia)" }, - { id: "pt-BR", label: "Português (Brasil)" }, - { id: "pt-PT", label: "Português (Portugal)" }, - { id: "hi-IN", label: "हिन्दी (भारत)" }, - { id: "ko-KR", label: "한국어(대한민국)" }, - { id: "zh-CN", label: "中文(中国大陆)" }, - { id: "zh-HK", label: "中文(香港)" }, - { id: "zh-TW", label: "中文(台灣)" }, - { id: "ja-JP", label: "日本語 (日本)" }, - { id: "yue-CN", label: "粤语(中国大陆)" }, -]; +import { useEffect, useState } from "react"; + +import { getDictationLanguages } from "../native/voiceTranscription"; +import type { DictationLanguage } from "../native/voiceTranscription.types"; export const DEVICE_DICTATION_LANGUAGE_LABEL = "Device language"; -export function isDictationLanguage(value: unknown): value is string { - return DICTATION_LANGUAGES.some((language) => language.id === value); +/** The languages this device can transcribe, or undefined while they load. */ +export function useDictationLanguages(): ReadonlyArray | undefined { + const [languages, setLanguages] = useState>(); + useEffect(() => { + let cancelled = false; + getDictationLanguages().then( + (loaded) => { + if (!cancelled) setLanguages(loaded); + }, + () => { + if (!cancelled) setLanguages([]); + }, + ); + return () => { + cancelled = true; + }; + }, []); + return languages; } -export function dictationLanguageLabel(id: string | null | undefined): string { - return ( - DICTATION_LANGUAGES.find((language) => language.id === id)?.label ?? - DEVICE_DICTATION_LANGUAGE_LABEL - ); +export function dictationLanguageLabel( + languages: ReadonlyArray | undefined, + id: string | null | undefined, +): string { + if (id == null) return DEVICE_DICTATION_LANGUAGE_LABEL; + return languages?.find((language) => language.id === id)?.label ?? id; } diff --git a/apps/mobile/src/native/voiceTranscription.ios.test.ts b/apps/mobile/src/native/voiceTranscription.ios.test.ts index 79351c9c07bbf..da2b764271525 100644 --- a/apps/mobile/src/native/voiceTranscription.ios.test.ts +++ b/apps/mobile/src/native/voiceTranscription.ios.test.ts @@ -6,6 +6,8 @@ import { VoiceTranscriptionError } from "@t3tools/client-runtime/voice-input"; const mocks = vi.hoisted(() => ({ isAvailable: vi.fn<(locale: string) => boolean>(), prepare: vi.fn<(locale: string) => Promise>(), + supportedLanguages: + vi.fn<() => Promise>>(), transcribe: vi.fn<(audio: ArrayBufferLike, locale: string) => Promise>(), readAudio: vi.fn<() => Promise>(), })); @@ -14,6 +16,7 @@ vi.mock("@react-native-ai/apple/src/NativeAppleTranscription", () => ({ default: { isAvailable: mocks.isAvailable, prepare: mocks.prepare, + supportedLanguages: mocks.supportedLanguages, transcribe: mocks.transcribe, }, })); @@ -24,7 +27,7 @@ vi.mock("expo-file-system", () => ({ }, })); -import { getLocalVoiceTranscriber } from "./voiceTranscription.ios"; +import { getDictationLanguages, getLocalVoiceTranscriber } from "./voiceTranscription.ios"; const audio = new ArrayBuffer(4); const nativeTranscript: TranscriptionResult = { @@ -154,3 +157,25 @@ describe("getLocalVoiceTranscriber", () => { }, ); }); + +describe("getDictationLanguages", () => { + it("lists what the device supports, sorted by name", async () => { + mocks.supportedLanguages.mockResolvedValue([ + { id: "pt-BR", label: "Português (Brasil)" }, + { id: "de-DE", label: "Deutsch (Deutschland)" }, + { id: "en-US", label: "English (US)" }, + ]); + + expect(await getDictationLanguages()).toEqual([ + { id: "de-DE", label: "Deutsch (Deutschland)" }, + { id: "en-US", label: "English (US)" }, + { id: "pt-BR", label: "Português (Brasil)" }, + ]); + }); + + it("is empty where the device cannot transcribe", async () => { + mocks.supportedLanguages.mockResolvedValue([]); + + expect(await getDictationLanguages()).toEqual([]); + }); +}); diff --git a/apps/mobile/src/native/voiceTranscription.ios.ts b/apps/mobile/src/native/voiceTranscription.ios.ts index d0741284787a2..2b1b15ca53dea 100644 --- a/apps/mobile/src/native/voiceTranscription.ios.ts +++ b/apps/mobile/src/native/voiceTranscription.ios.ts @@ -9,6 +9,8 @@ import { type VoiceTranscriptionOptions, } from "@t3tools/client-runtime/voice-input"; +import type { DictationLanguage } from "./voiceTranscription.types"; + function getDeviceLocale(): string { return Intl.DateTimeFormat().resolvedOptions().locale; } @@ -39,6 +41,11 @@ export function getLocalVoiceTranscriber(preferredLocale?: string): VoiceTranscr return { prepare: (options) => prepareVoiceTranscription(locale, options) }; } +export async function getDictationLanguages(): Promise> { + const languages = await AppleTranscription.supportedLanguages(); + return [...languages].sort((a, b) => a.label.localeCompare(b.label)); +} + async function prepareVoiceTranscription( locale: string, { signal }: VoiceTranscriptionOptions, diff --git a/apps/mobile/src/native/voiceTranscription.ts b/apps/mobile/src/native/voiceTranscription.ts index 8008a2d9ac522..ab030691a30f8 100644 --- a/apps/mobile/src/native/voiceTranscription.ts +++ b/apps/mobile/src/native/voiceTranscription.ts @@ -1,5 +1,11 @@ import type { VoiceTranscriber } from "@t3tools/client-runtime/voice-input"; +import type { DictationLanguage } from "./voiceTranscription.types"; + export function getLocalVoiceTranscriber(_preferredLocale?: string): VoiceTranscriber | null { return null; } + +export function getDictationLanguages(): Promise> { + return Promise.resolve([]); +} diff --git a/apps/mobile/src/native/voiceTranscription.types.ts b/apps/mobile/src/native/voiceTranscription.types.ts new file mode 100644 index 0000000000000..dee7210e766f7 --- /dev/null +++ b/apps/mobile/src/native/voiceTranscription.types.ts @@ -0,0 +1,4 @@ +export interface DictationLanguage { + readonly id: string; + readonly label: string; +} diff --git a/apps/mobile/src/persistence/mobile-preferences.ts b/apps/mobile/src/persistence/mobile-preferences.ts index ea8b3bec84a89..8ad9151ee7657 100644 --- a/apps/mobile/src/persistence/mobile-preferences.ts +++ b/apps/mobile/src/persistence/mobile-preferences.ts @@ -16,7 +16,6 @@ import { } from "@t3tools/contracts"; import type { ComposerEnterBehavior } from "../lib/composerEnterBehavior"; import type { FollowUpBehavior } from "../lib/followUpBehavior"; -import { isDictationLanguage } from "../lib/dictationLanguages"; import { isMicrophoneKind, type MicrophoneEntry } from "../lib/microphonePriority"; import { MOBILE_THEME_IDS, type MobileThemeId, type MobileThemeMode } from "../lib/mobileTheme"; import * as MobileDatabase from "./mobile-database"; @@ -73,7 +72,7 @@ export interface Preferences { readonly composerEnterBehavior?: ComposerEnterBehavior; readonly followUpBehavior?: FollowUpBehavior; readonly microphones?: ReadonlyArray; - /** An id from `DICTATION_LANGUAGES`, or null for the device language. */ + /** A BCP 47 tag the device can transcribe, or null for the device language. */ readonly voiceInputLocale?: string | null; readonly projectGroupingEnabled?: boolean; readonly projectGroupingMode?: SidebarProjectGroupingMode; @@ -127,6 +126,13 @@ export class MobilePreferencesStore extends Context.Service< } >()("@t3tools/mobile/persistence/MobilePreferencesStore") {} +// Shape only; whether the device can transcribe the tag is checked when preparing voice input. +const LANGUAGE_TAG = /^[A-Za-z]{2,3}(-[A-Za-z0-9]{2,8})*$/; + +function isLanguageTag(value: unknown): value is string { + return typeof value === "string" && LANGUAGE_TAG.test(value); +} + function sanitizePreferences(parsed: Preferences): Preferences { const preferences: { pullRequestHideTestFiles?: boolean; @@ -244,7 +250,7 @@ function sanitizePreferences(parsed: Preferences): Preferences { : []; }); } - if (isDictationLanguage(parsed.voiceInputLocale) || parsed.voiceInputLocale === null) { + if (parsed.voiceInputLocale === null || isLanguageTag(parsed.voiceInputLocale)) { preferences.voiceInputLocale = parsed.voiceInputLocale; } if (typeof parsed.projectGroupingEnabled === "boolean") { diff --git a/apps/mobile/src/state/preferences.test.ts b/apps/mobile/src/state/preferences.test.ts index ce112588b8d25..4b8db9a2f642d 100644 --- a/apps/mobile/src/state/preferences.test.ts +++ b/apps/mobile/src/state/preferences.test.ts @@ -98,13 +98,16 @@ function makePreferencesStore(initialPayload: MobilePreferences.Preferences) { } describe("mobile preferences store", () => { - it.effect("keeps a null dictation language and drops an unknown one", () => + it.effect("keeps a null or well-formed dictation language and drops a malformed one", () => Effect.gen(function* () { const cleared = yield* makePreferencesStore({ voiceInputLocale: null }); expect(yield* cleared.store.load).toEqual({ voiceInputLocale: null }); - const unknown = yield* makePreferencesStore({ voiceInputLocale: "xx-XX" }); - expect(yield* unknown.store.load).toEqual({}); + const chosen = yield* makePreferencesStore({ voiceInputLocale: "yue-Hant-HK" }); + expect(yield* chosen.store.load).toEqual({ voiceInputLocale: "yue-Hant-HK" }); + + const malformed = yield* makePreferencesStore({ voiceInputLocale: "Portuguese" }); + expect(yield* malformed.store.load).toEqual({}); }), ); }); From 546c05a2c40ab4b7c7796e15be2779abf154ed8e Mon Sep 17 00:00:00 2001 From: Gabriel Taveira Date: Wed, 28 Oct 2026 10:22:07 -0300 Subject: [PATCH 6/6] fix(mobile): preserve dictation language extensions --- apps/mobile/src/persistence/mobile-preferences.ts | 3 ++- apps/mobile/src/state/preferences.test.ts | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/apps/mobile/src/persistence/mobile-preferences.ts b/apps/mobile/src/persistence/mobile-preferences.ts index 2d72a2eebebc0..83e0e839e572d 100644 --- a/apps/mobile/src/persistence/mobile-preferences.ts +++ b/apps/mobile/src/persistence/mobile-preferences.ts @@ -168,7 +168,8 @@ export class MobilePreferencesStore extends Context.Service< >()("@t3tools/mobile/persistence/MobilePreferencesStore") {} // Shape only; whether the device can transcribe the tag is checked when preparing voice input. -const LANGUAGE_TAG = /^[A-Za-z]{2,3}(-[A-Za-z0-9]{2,8})*$/; +const LANGUAGE_TAG = + /^[A-Za-z]{2,8}(?:-[A-Za-z0-9]{2,8})*(?:-[0-9A-WY-Za-wy-z](?:-[A-Za-z0-9]{2,8})+)*(?:-[xX](?:-[A-Za-z0-9]{1,8})+)?$/; function isLanguageTag(value: unknown): value is string { return typeof value === "string" && LANGUAGE_TAG.test(value); diff --git a/apps/mobile/src/state/preferences.test.ts b/apps/mobile/src/state/preferences.test.ts index 3c805eb1b87cb..7b6d7a90964ef 100644 --- a/apps/mobile/src/state/preferences.test.ts +++ b/apps/mobile/src/state/preferences.test.ts @@ -106,6 +106,15 @@ describe("mobile preferences store", () => { const chosen = yield* makePreferencesStore({ voiceInputLocale: "yue-Hant-HK" }); expect(yield* chosen.store.load).toEqual({ voiceInputLocale: "yue-Hant-HK" }); + const extended = yield* makePreferencesStore({ voiceInputLocale: "en-US-u-ca-gregory" }); + expect(yield* extended.store.load).toEqual({ voiceInputLocale: "en-US-u-ca-gregory" }); + + const privateUse = yield* makePreferencesStore({ voiceInputLocale: "en-US-x-a" }); + expect(yield* privateUse.store.load).toEqual({ voiceInputLocale: "en-US-x-a" }); + + const incomplete = yield* makePreferencesStore({ voiceInputLocale: "en-US-u" }); + expect(yield* incomplete.store.load).toEqual({}); + const malformed = yield* makePreferencesStore({ voiceInputLocale: "Portuguese" }); expect(yield* malformed.store.load).toEqual({}); }),