mirror of
https://github.com/home-assistant/frontend.git
synced 2025-11-15 14:00:38 +00:00
Translate integration filters (#26728)
Co-authored-by: Bram Kragten <mail@bramkragten.nl>
This commit is contained in:
@@ -6,8 +6,9 @@ import { repeat } from "lit/directives/repeat";
|
|||||||
import memoizeOne from "memoize-one";
|
import memoizeOne from "memoize-one";
|
||||||
import { fireEvent } from "../common/dom/fire_event";
|
import { fireEvent } from "../common/dom/fire_event";
|
||||||
import { stringCompare } from "../common/string/compare";
|
import { stringCompare } from "../common/string/compare";
|
||||||
|
import type { LocalizeFunc } from "../common/translations/localize";
|
||||||
import type { IntegrationManifest } from "../data/integration";
|
import type { IntegrationManifest } from "../data/integration";
|
||||||
import { fetchIntegrationManifests } from "../data/integration";
|
import { fetchIntegrationManifests, domainToName } from "../data/integration";
|
||||||
import { haStyleScrollbar } from "../resources/styles";
|
import { haStyleScrollbar } from "../resources/styles";
|
||||||
import type { HomeAssistant } from "../types";
|
import type { HomeAssistant } from "../types";
|
||||||
import "./ha-check-list-item";
|
import "./ha-check-list-item";
|
||||||
@@ -63,7 +64,12 @@ export class HaFilterIntegrations extends LitElement {
|
|||||||
multi
|
multi
|
||||||
>
|
>
|
||||||
${repeat(
|
${repeat(
|
||||||
this._integrations(this._manifests, this._filter, this.value),
|
this._integrations(
|
||||||
|
this.hass.localize,
|
||||||
|
this._manifests,
|
||||||
|
this._filter,
|
||||||
|
this.value
|
||||||
|
),
|
||||||
(i) => i.domain,
|
(i) => i.domain,
|
||||||
(integration) =>
|
(integration) =>
|
||||||
html`<ha-check-list-item
|
html`<ha-check-list-item
|
||||||
@@ -79,7 +85,7 @@ export class HaFilterIntegrations extends LitElement {
|
|||||||
.domain=${integration.domain}
|
.domain=${integration.domain}
|
||||||
brand-fallback
|
brand-fallback
|
||||||
></ha-domain-icon>
|
></ha-domain-icon>
|
||||||
${integration.name || integration.domain}
|
${integration.name}
|
||||||
</ha-check-list-item>`
|
</ha-check-list-item>`
|
||||||
)}
|
)}
|
||||||
</ha-list> `
|
</ha-list> `
|
||||||
@@ -108,11 +114,21 @@ export class HaFilterIntegrations extends LitElement {
|
|||||||
|
|
||||||
protected async firstUpdated() {
|
protected async firstUpdated() {
|
||||||
this._manifests = await fetchIntegrationManifests(this.hass);
|
this._manifests = await fetchIntegrationManifests(this.hass);
|
||||||
|
this.hass.loadBackendTranslation("title");
|
||||||
}
|
}
|
||||||
|
|
||||||
private _integrations = memoizeOne(
|
private _integrations = memoizeOne(
|
||||||
(manifest: IntegrationManifest[], filter: string | undefined, _value) =>
|
(
|
||||||
|
localize: LocalizeFunc,
|
||||||
|
manifest: IntegrationManifest[],
|
||||||
|
filter: string | undefined,
|
||||||
|
_value
|
||||||
|
) =>
|
||||||
manifest
|
manifest
|
||||||
|
.map((mnfst) => ({
|
||||||
|
...mnfst,
|
||||||
|
name: domainToName(localize, mnfst.domain, mnfst),
|
||||||
|
}))
|
||||||
.filter(
|
.filter(
|
||||||
(mnfst) =>
|
(mnfst) =>
|
||||||
(!mnfst.integration_type ||
|
(!mnfst.integration_type ||
|
||||||
@@ -124,11 +140,7 @@ export class HaFilterIntegrations extends LitElement {
|
|||||||
mnfst.domain.toLowerCase().includes(filter))
|
mnfst.domain.toLowerCase().includes(filter))
|
||||||
)
|
)
|
||||||
.sort((a, b) =>
|
.sort((a, b) =>
|
||||||
stringCompare(
|
stringCompare(a.name, b.name, this.hass.locale.language)
|
||||||
a.name || a.domain,
|
|
||||||
b.name || b.domain,
|
|
||||||
this.hass.locale.language
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user