Skip to content

Commit 546c05a

Browse files
committed
fix(mobile): preserve dictation language extensions
1 parent 564d1a4 commit 546c05a

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

‎apps/mobile/src/persistence/mobile-preferences.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,8 @@ export class MobilePreferencesStore extends Context.Service<
168168
>()("@t3tools/mobile/persistence/MobilePreferencesStore") {}
169169

170170
// Shape only; whether the device can transcribe the tag is checked when preparing voice input.
171-
const LANGUAGE_TAG = /^[A-Za-z]{2,3}(-[A-Za-z0-9]{2,8})*$/;
171+
const LANGUAGE_TAG =
172+
/^[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})+)?$/;
172173

173174
function isLanguageTag(value: unknown): value is string {
174175
return typeof value === "string" && LANGUAGE_TAG.test(value);

‎apps/mobile/src/state/preferences.test.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,15 @@ describe("mobile preferences store", () => {
106106
const chosen = yield* makePreferencesStore({ voiceInputLocale: "yue-Hant-HK" });
107107
expect(yield* chosen.store.load).toEqual({ voiceInputLocale: "yue-Hant-HK" });
108108

109+
const extended = yield* makePreferencesStore({ voiceInputLocale: "en-US-u-ca-gregory" });
110+
expect(yield* extended.store.load).toEqual({ voiceInputLocale: "en-US-u-ca-gregory" });
111+
112+
const privateUse = yield* makePreferencesStore({ voiceInputLocale: "en-US-x-a" });
113+
expect(yield* privateUse.store.load).toEqual({ voiceInputLocale: "en-US-x-a" });
114+
115+
const incomplete = yield* makePreferencesStore({ voiceInputLocale: "en-US-u" });
116+
expect(yield* incomplete.store.load).toEqual({});
117+
109118
const malformed = yield* makePreferencesStore({ voiceInputLocale: "Portuguese" });
110119
expect(yield* malformed.store.load).toEqual({});
111120
}),

0 commit comments

Comments
 (0)