mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-19 07:16:39 +00:00
Voice wizard: Use test message in tts language (#22882)
* Voice wizard: Use test message in tts language * catch none existing lang
This commit is contained in:
parent
995155696f
commit
b7ef633a3e
@ -24,6 +24,7 @@ import "../../panels/lovelace/entity-rows/hui-select-entity-row";
|
|||||||
import type { HomeAssistant } from "../../types";
|
import type { HomeAssistant } from "../../types";
|
||||||
import { AssistantSetupStyles } from "./styles";
|
import { AssistantSetupStyles } from "./styles";
|
||||||
import { STEP } from "./voice-assistant-setup-dialog";
|
import { STEP } from "./voice-assistant-setup-dialog";
|
||||||
|
import { getTranslation } from "../../util/common-translation";
|
||||||
|
|
||||||
@customElement("ha-voice-assistant-setup-step-success")
|
@customElement("ha-voice-assistant-setup-step-success")
|
||||||
export class HaVoiceAssistantSetupStepSuccess extends LitElement {
|
export class HaVoiceAssistantSetupStepSuccess extends LitElement {
|
||||||
@ -213,8 +214,24 @@ export class HaVoiceAssistantSetupStepSuccess extends LitElement {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private _testTts() {
|
private async _testTts() {
|
||||||
this._announce("Hello, how can I help you?");
|
const [pipeline] = await this._getPipeline();
|
||||||
|
|
||||||
|
if (!pipeline) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pipeline.language !== this.hass.locale.language) {
|
||||||
|
try {
|
||||||
|
const result = await getTranslation(null, pipeline.language, false);
|
||||||
|
this._announce(result.data["ui.dialogs.tts-try.message_example"]);
|
||||||
|
return;
|
||||||
|
} catch (e) {
|
||||||
|
// ignore fallback to user language
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this._announce(this.hass.localize("ui.dialogs.tts-try.message_example"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private async _announce(message: string) {
|
private async _announce(message: string) {
|
||||||
|
@ -135,14 +135,15 @@ export function getLocalLanguage() {
|
|||||||
|
|
||||||
export async function getTranslation(
|
export async function getTranslation(
|
||||||
fragment: string | null,
|
fragment: string | null,
|
||||||
language: string
|
language: string,
|
||||||
|
fallback = true
|
||||||
) {
|
) {
|
||||||
const metadata = translationMetadata.translations[language];
|
const metadata = translationMetadata.translations[language];
|
||||||
if (!metadata?.hash) {
|
if (!metadata?.hash) {
|
||||||
if (language !== "en") {
|
if (fallback && language !== "en") {
|
||||||
return getTranslation(fragment, "en");
|
return getTranslation(fragment, "en");
|
||||||
}
|
}
|
||||||
throw new Error("Language en is not found in metadata");
|
throw new Error(`Language '${language}' is not found in metadata`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// nl-abcd.jon or logbook/nl-abcd.json
|
// nl-abcd.jon or logbook/nl-abcd.json
|
||||||
|
Loading…
x
Reference in New Issue
Block a user