fix(voice): messages worded before reaching the status also follow a language change (#1661)

The radio and push-to-talk helpers shared by both voice providers now pass
English catalog text, and the OpenAI controller words its detail when shown,
like the Gemini session. A token failure without a server message carries
its status as sourceParams, so it is worded again with the number. The docs
say sourceDetail is the message as given, catalog text when it is the app's
own.
This commit is contained in:
Sameh Khamis committed 2026-11-10 18:11:07 -08:00
1 parent 44dd6d48a8
commit 874f83ba48
9 files changed
+107 -19

No files matched your search

+28 -8
View File
@@ -361,23 +361,31 @@ export class GeminiSessionController {
}
/**
* @param {{missingKey?: boolean}} [options] True when the server has no
* Gemini key: the control then drops its microphone hint.
* @param {{missingKey?: boolean, params?: object}} [options] `missingKey`
* is true when the server has no Gemini key: the control then drops its
* microphone hint. `params` fill the placeholders of `detail`.
*/
setStatus(status, detail, recovery, { missingKey = false } = {}) {
setStatus(
status,
detail,
recovery,
{ missingKey = false, params = null } = {},
) {
this.status = status;
if (status === 'listening' && this.input.pushToTalkMode)
detail = this.input.pushToTalkKeyHeld
? msg('Release Space to send')
: msg('Hold Space to talk');
// `detail` is worded in the current language; `sourceDetail` keeps the
// English catalog text, so a view can word it again after a language
// change.
// message as given (English catalog text, with `sourceParams` for its
// placeholders, when it is ours), so a view can word it again after a
// language change.
const event = {
type: 'state',
state: status,
detail: translateKnown(detail),
detail: params ? t(detail, params) : translateKnown(detail),
...(typeof detail === 'string' && { sourceDetail: detail }),
...(params && { sourceParams: params }),
};
if (recovery) event.recovery = translateKnown(recovery);
if (missingKey) event.missingKey = true;
@@ -603,6 +611,15 @@ export class GeminiSessionController {
}),
),
typeof data?.code === 'string' ? { code: data.code } : {},
// The status words this again in the current language when shown.
typeof data?.error === 'string'
? {}
: {
wording: {
text: msg('Gemini token request failed (HTTP {status})'),
params: { status: response.status },
},
},
);
if (
typeof data?.model !== 'string' ||
@@ -976,11 +993,14 @@ export class GeminiSessionController {
)
: error?.name === 'TimeoutError'
? msg('Gemini connection timed out. Try again.')
: error?.message || msg('Gemini voice could not start');
this.lastError = detail;
: error?.wording?.text ||
error?.message ||
msg('Gemini voice could not start');
this.lastError = error?.wording ? error.message : detail;
this.stop({ preserveStatus: true });
this.setStatus('error', detail, recovery, {
missingKey: error?.code === 'API_KEY_MISSING',
params: error?.wording?.params,
});
}