From c0c83d372167d61350328a1444c5152cd2c98845 Mon Sep 17 00:00:00 2001 From: Paul Bottein Date: Fri, 17 Mar 2023 16:26:53 +0100 Subject: [PATCH] Add analytics translations (#15821) * Add analytics translations * Move translations to panels * Fix learn more link --- src/components/ha-analytics-learn-more.ts | 11 ---- src/components/ha-analytics.ts | 62 +++++++++++-------- src/onboarding/onboarding-analytics.ts | 17 ++--- src/panels/config/core/ha-config-analytics.ts | 19 +++--- src/translations/en.json | 46 +++++++++++++- 5 files changed, 102 insertions(+), 53 deletions(-) delete mode 100644 src/components/ha-analytics-learn-more.ts diff --git a/src/components/ha-analytics-learn-more.ts b/src/components/ha-analytics-learn-more.ts deleted file mode 100644 index e806b2e459..0000000000 --- a/src/components/ha-analytics-learn-more.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { html } from "lit"; -import { HomeAssistant } from "../types"; -import { documentationUrl } from "../util/documentation-url"; - -export const analyticsLearnMore = (hass: HomeAssistant) => html` - How we process your data -`; diff --git a/src/components/ha-analytics.ts b/src/components/ha-analytics.ts index 33756e4c28..debacb9a97 100644 --- a/src/components/ha-analytics.ts +++ b/src/components/ha-analytics.ts @@ -9,18 +9,7 @@ import "./ha-settings-row"; import "./ha-switch"; import type { HaSwitch } from "./ha-switch"; -const ADDITIONAL_PREFERENCES = [ - { - key: "usage", - title: "Usage", - description: "Details of what you use with Home Assistant", - }, - { - key: "statistics", - title: "Statistical data", - description: "Counts containing total number of datapoints", - }, -]; +const ADDITIONAL_PREFERENCES = ["usage", "statistics"] as const; declare global { interface HASSDomEvents { @@ -34,15 +23,25 @@ export class HaAnalytics extends LitElement { @property({ attribute: false }) public analytics?: Analytics; + @property({ attribute: "translation_key_panel" }) public translationKeyPanel: + | "page-onboarding" + | "config" = "config"; + protected render(): TemplateResult { const loading = this.analytics === undefined; const baseEnabled = !loading && this.analytics!.preferences.base; return html` - Basic analytics + + ${this.hass.localize( + `ui.panel.${this.translationKeyPanel}.analytics.preferences.base.title` + )} + - This includes information about your system. + ${this.hass.localize( + `ui.panel.${this.translationKeyPanel}.analytics.preferences.base.description` + )} html` - - ${preference.title} + + ${this.hass.localize( + `ui.panel.${this.translationKeyPanel}.analytics.preferences.${preference}.title` + )} - - ${preference.description} + + ${this.hass.localize( + `ui.panel.${this.translationKeyPanel}.analytics.preferences.${preference}.description` + )} ${!baseEnabled ? html` - You need to enable basic analytics for this option to be - available + ${this.hass.localize( + `ui.panel.${this.translationKeyPanel}.analytics.need_base_enabled` + )} ` : ""} @@ -84,9 +88,15 @@ export class HaAnalytics extends LitElement { ` )} - Diagnostics + + ${this.hass.localize( + `ui.panel.${this.translationKeyPanel}.analytics.preferences.diagnostics.title` + )} + - Share crash reports when unexpected errors occur. + ${this.hass.localize( + `ui.panel.${this.translationKeyPanel}.analytics.preferences.diagnostics.description` + )} entry.key === preference) && + ADDITIONAL_PREFERENCES.some((entry) => entry === preference) && target.checked ) { preferences.base = true; diff --git a/src/onboarding/onboarding-analytics.ts b/src/onboarding/onboarding-analytics.ts index 3e8c1bfbf8..cbc4b6aad7 100644 --- a/src/onboarding/onboarding-analytics.ts +++ b/src/onboarding/onboarding-analytics.ts @@ -4,10 +4,10 @@ import { customElement, property, state } from "lit/decorators"; import { fireEvent } from "../common/dom/fire_event"; import { LocalizeFunc } from "../common/translations/localize"; import "../components/ha-analytics"; -import { analyticsLearnMore } from "../components/ha-analytics-learn-more"; import { Analytics, setAnalyticsPreferences } from "../data/analytics"; import { onboardAnalyticsStep } from "../data/onboarding"; import type { HomeAssistant } from "../types"; +import { documentationUrl } from "../util/documentation-url"; @customElement("onboarding-analytics") class OnboardingAnalytics extends LitElement { @@ -23,12 +23,9 @@ class OnboardingAnalytics extends LitElement { protected render(): TemplateResult { return html` -

- Share anonymized information from your installation to help make Home - Assistant better and help us convince manufacturers to add local control - and privacy-focused features. -

+

${this.hass.localize("ui.panel.page-onboarding.analytics.intro")}

${this.localize("ui.panel.page-onboarding.analytics.finish")} - ${analyticsLearnMore(this.hass)} + + ${this.hass.localize("ui.panel.page-onboarding.analytics.learn_more")} + `; } diff --git a/src/panels/config/core/ha-config-analytics.ts b/src/panels/config/core/ha-config-analytics.ts index a9a90b3099..4c506ff7eb 100644 --- a/src/panels/config/core/ha-config-analytics.ts +++ b/src/panels/config/core/ha-config-analytics.ts @@ -10,7 +10,6 @@ import { import { customElement, property, state } from "lit/decorators"; import { isComponentLoaded } from "../../../common/config/is_component_loaded"; import "../../../components/ha-analytics"; -import { analyticsLearnMore } from "../../../components/ha-analytics-learn-more"; import "../../../components/ha-card"; import "../../../components/ha-checkbox"; import "../../../components/ha-settings-row"; @@ -21,6 +20,7 @@ import { } from "../../../data/analytics"; import { haStyle } from "../../../resources/styles"; import type { HomeAssistant } from "../../../types"; +import { documentationUrl } from "../../../util/documentation-url"; @customElement("ha-config-analytics") class ConfigAnalytics extends LitElement { @@ -41,12 +41,9 @@ class ConfigAnalytics extends LitElement {
${error ? html`
${error}
` : ""} -

- Share anonymized information from your installation to help make - Home Assistant better and help us convince manufacturers to add - local control and privacy-focused features. -

+

${this.hass.localize("ui.panel.config.analytics.intro")}

- + `; } diff --git a/src/translations/en.json b/src/translations/en.json index 112d389e3f..9675fec300 100755 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -3753,7 +3753,28 @@ }, "analytics": { "caption": "Analytics", - "description": "Learn how to share data to improve Home Assistant" + "description": "Learn how to share data to improve Home Assistant", + "preferences": { + "base": { + "title": "Basic analytics", + "description": "This includes information about your system." + }, + "usage": { + "title": "Usage", + "description": "Details of what you use with Home Assistant" + }, + "statistics": { + "title": "Statistical data", + "description": "Counts containing total number of datapoints." + }, + "diagnostics": { + "title": "Diagnostics", + "description": "Share crash reports when unexpected errors occur." + } + }, + "need_base_enabled": "You need to enable basic analytics for this option to be available", + "learn_more": "How we process your data", + "intro": "Share anonymized information from your installation to help make Home Assistant better and help us convince manufacturers to add local control and privacy-focused features." }, "network": { "caption": "Network", @@ -5026,7 +5047,28 @@ "finish": "Finish" }, "analytics": { - "finish": "Next" + "finish": "Next", + "preferences": { + "base": { + "title": "[%key:ui::panel::config::analytics::preferences::base::title%]", + "description": "[%key:ui::panel::config::analytics::preferences::base::description%]" + }, + "usage": { + "title": "[%key:ui::panel::config::analytics::preferences::usage::title%]", + "description": "[%key:ui::panel::config::analytics::preferences::usage::description%]" + }, + "statistics": { + "title": "[%key:ui::panel::config::analytics::preferences::statistics::title%]", + "description": "[%key:ui::panel::config::analytics::preferences::statistics::description%]" + }, + "diagnostics": { + "title": "[%key:ui::panel::config::analytics::preferences::diagnostics::title%]", + "description": "[%key:ui::panel::config::analytics::preferences::diagnostics::description%]" + } + }, + "need_base_enabled": "[%key:ui::panel::config::analytics::need_base_enabled%]", + "learn_more": "[%key:ui::panel::config::analytics::learn_more%]", + "intro": "[%key:ui::panel::config::analytics::intro%]" }, "restore": { "description": "Alternatively you can restore from a previous backup.",