mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-27 19:26:36 +00:00
Write log on translation error (#20430)
* Write log on translation error * Update ha-config-devices-dashboard.ts --------- Co-authored-by: Franck Nijhof <git@frenck.dev>
This commit is contained in:
parent
35cf3063cb
commit
b091d4f298
@ -2,6 +2,7 @@ import IntlMessageFormat from "intl-messageformat";
|
|||||||
import type { HTMLTemplateResult } from "lit";
|
import type { HTMLTemplateResult } from "lit";
|
||||||
import { polyfillLocaleData } from "../../resources/locale-data-polyfill";
|
import { polyfillLocaleData } from "../../resources/locale-data-polyfill";
|
||||||
import { Resources, TranslationDict } from "../../types";
|
import { Resources, TranslationDict } from "../../types";
|
||||||
|
import { fireEvent } from "../dom/fire_event";
|
||||||
|
|
||||||
// Exclude some patterns from key type checking for now
|
// Exclude some patterns from key type checking for now
|
||||||
// These are intended to be removed as errors are fixed
|
// These are intended to be removed as errors are fixed
|
||||||
@ -81,7 +82,9 @@ export interface FormatsType {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
export const computeLocalize = async <Keys extends string = LocalizeKeys>(
|
export const computeLocalize = async <Keys extends string = LocalizeKeys>(
|
||||||
cache: any,
|
cache: HTMLElement & {
|
||||||
|
_localizationCache?: Record<string, IntlMessageFormat>;
|
||||||
|
},
|
||||||
language: string,
|
language: string,
|
||||||
resources: Resources,
|
resources: Resources,
|
||||||
formats?: FormatsType
|
formats?: FormatsType
|
||||||
@ -107,7 +110,7 @@ export const computeLocalize = async <Keys extends string = LocalizeKeys>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const messageKey = key + translatedValue;
|
const messageKey = key + translatedValue;
|
||||||
let translatedMessage = cache._localizationCache[messageKey] as
|
let translatedMessage = cache._localizationCache![messageKey] as
|
||||||
| IntlMessageFormat
|
| IntlMessageFormat
|
||||||
| undefined;
|
| undefined;
|
||||||
|
|
||||||
@ -121,7 +124,7 @@ export const computeLocalize = async <Keys extends string = LocalizeKeys>(
|
|||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
return "Translation error: " + err.message;
|
return "Translation error: " + err.message;
|
||||||
}
|
}
|
||||||
cache._localizationCache[messageKey] = translatedMessage;
|
cache._localizationCache![messageKey] = translatedMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
let argObject = {};
|
let argObject = {};
|
||||||
@ -137,6 +140,12 @@ export const computeLocalize = async <Keys extends string = LocalizeKeys>(
|
|||||||
try {
|
try {
|
||||||
return translatedMessage.format<string>(argObject) as string;
|
return translatedMessage.format<string>(argObject) as string;
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.error("Translation error", key, language, err);
|
||||||
|
fireEvent(cache, "write_log", {
|
||||||
|
level: "error",
|
||||||
|
message: `Failed to format translation for key '${key}' in language '${language}'. ${err}`,
|
||||||
|
});
|
||||||
return "Translation " + err;
|
return "Translation " + err;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -496,9 +496,7 @@ export class HaTabsSubpageDataTable extends LitElement {
|
|||||||
${this.showFilters && !showPane
|
${this.showFilters && !showPane
|
||||||
? html`<ha-dialog
|
? html`<ha-dialog
|
||||||
open
|
open
|
||||||
.heading=${localize("ui.components.subpage-data-table.filters", {
|
.heading=${localize("ui.components.subpage-data-table.filters")}
|
||||||
number: this.data.length,
|
|
||||||
})}
|
|
||||||
>
|
>
|
||||||
<ha-dialog-header slot="heading">
|
<ha-dialog-header slot="heading">
|
||||||
<ha-icon-button
|
<ha-icon-button
|
||||||
@ -510,9 +508,7 @@ export class HaTabsSubpageDataTable extends LitElement {
|
|||||||
)}
|
)}
|
||||||
></ha-icon-button>
|
></ha-icon-button>
|
||||||
<span slot="title"
|
<span slot="title"
|
||||||
>${localize("ui.components.subpage-data-table.filters", {
|
>${localize("ui.components.subpage-data-table.filters")}</span
|
||||||
number: this.data.length,
|
|
||||||
})}</span
|
|
||||||
>
|
>
|
||||||
${this.filters
|
${this.filters
|
||||||
? html`<ha-icon-button
|
? html`<ha-icon-button
|
||||||
|
Loading…
x
Reference in New Issue
Block a user