Fix a bunch of translation strings (#5597)

* Fix a bunch of translation strings

* Fallback on default if no device class translations
This commit is contained in:
Paulus Schoutsen 2020-04-23 04:07:40 -07:00 committed by GitHub
parent 13a8bf6993
commit fc20fd32f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 66 additions and 39 deletions

View File

@ -96,7 +96,6 @@ export const computeStateDisplay = (
return legacyComputeStateDisplay(localize, stateObj, language); return legacyComputeStateDisplay(localize, stateObj, language);
} }
// Real code.
if (stateObj.state === UNKNOWN || stateObj.state === UNAVAILABLE) { if (stateObj.state === UNKNOWN || stateObj.state === UNAVAILABLE) {
return localize(`state.default.${stateObj.state}`); return localize(`state.default.${stateObj.state}`);
} }
@ -141,9 +140,15 @@ export const computeStateDisplay = (
return formatDateTime(date, language); return formatDateTime(date, language);
} }
const deviceClass = stateObj.attributes.device_class || "_";
return ( return (
localize(`component.${domain}.state.${deviceClass}.${stateObj.state}`) || // Return device class translation
(stateObj.attributes.device_class &&
localize(
`component.${domain}.state.${stateObj.attributes.device_class}.${stateObj.state}`
)) ||
// Return default translation
localize(`component.${domain}.state._.${stateObj.state}`) ||
// We don't know! Return the raw state.
stateObj.state stateObj.state
); );
}; };

View File

@ -110,7 +110,7 @@ class HaClimateState extends LocalizeMixin(PolymerElement) {
} }
_localizeState(localize, stateObj) { _localizeState(localize, stateObj) {
const stateString = localize(`state.climate.${stateObj.state}`); const stateString = localize(`component.climate.state._.${stateObj.state}`);
return stateObj.attributes.hvac_action return stateObj.attributes.hvac_action
? `${localize( ? `${localize(
`state_attributes.climate.hvac_action.${stateObj.attributes.hvac_action}` `state_attributes.climate.hvac_action.${stateObj.attributes.hvac_action}`

View File

@ -76,7 +76,7 @@ class HaVacuumState extends LocalizeMixin(PolymerElement) {
? this.localize( ? this.localize(
`ui.card.vacuum.actions.${STATES_INTERCEPTABLE[state].action}` `ui.card.vacuum.actions.${STATES_INTERCEPTABLE[state].action}`
) )
: this.localize(`state.vacuum.${state}`); : this.localize(`component.vacuum._.${state}`);
} }
_callService(ev) { _callService(ev) {

View File

@ -2,6 +2,7 @@ import { html } from "@polymer/polymer/lib/utils/html-tag";
/* eslint-plugin-disable lit */ /* eslint-plugin-disable lit */
import { PolymerElement } from "@polymer/polymer/polymer-element"; import { PolymerElement } from "@polymer/polymer/polymer-element";
import LocalizeMixin from "../mixins/localize-mixin"; import LocalizeMixin from "../mixins/localize-mixin";
import { computeStateDisplay } from "../common/entity/compute_state_display";
/* /*
* @appliesMixin LocalizeMixin * @appliesMixin LocalizeMixin
@ -32,7 +33,7 @@ class HaWaterHeaterState extends LocalizeMixin(PolymerElement) {
</style> </style>
<div class="target"> <div class="target">
<span class="state-label"> [[_localizeState(stateObj.state)]] </span> <span class="state-label"> [[_localizeState(stateObj)]] </span>
[[computeTarget(hass, stateObj)]] [[computeTarget(hass, stateObj)]]
</div> </div>
@ -67,8 +68,8 @@ class HaWaterHeaterState extends LocalizeMixin(PolymerElement) {
return ""; return "";
} }
_localizeState(state) { _localizeState(stateObj) {
return this.localize(`state.water_heater.${state}`) || state; return computeStateDisplay(this.hass.localize, stateObj);
} }
} }
customElements.define("ha-water_heater-state", HaWaterHeaterState); customElements.define("ha-water_heater-state", HaWaterHeaterState);

View File

@ -185,7 +185,7 @@ class MoreInfoClimate extends LitElement {
.map( .map(
(mode) => html` (mode) => html`
<paper-item item-name=${mode}> <paper-item item-name=${mode}>
${hass.localize(`state.climate.${mode}`)} ${hass.localize(`component.climate.state._.${mode}`)}
</paper-item> </paper-item>
` `
)} )}

View File

@ -246,7 +246,7 @@ class MoreInfoWaterHeater extends LocalizeMixin(EventsMixin(PolymerElement)) {
} }
_localizeOperationMode(localize, mode) { _localizeOperationMode(localize, mode) {
return localize(`state.water_heater.${mode}`) || mode; return localize(`component.water_heater.state._.${mode}`) || mode;
} }
} }

View File

@ -11,6 +11,7 @@ import { PersitentNotificationEntity } from "../../data/persistent_notification"
import { HomeAssistant } from "../../types"; import { HomeAssistant } from "../../types";
import "./notification-item-template"; import "./notification-item-template";
import { domainToName } from "../../data/integration"; import { domainToName } from "../../data/integration";
import { computeStateDisplay } from "../../common/entity/compute_state_display";
@customElement("configurator-notification-item") @customElement("configurator-notification-item")
export class HuiConfiguratorNotificationItem extends LitElement { export class HuiConfiguratorNotificationItem extends LitElement {
@ -38,8 +39,10 @@ export class HuiConfiguratorNotificationItem extends LitElement {
</div> </div>
<mwc-button slot="actions" @click="${this._handleClick}" <mwc-button slot="actions" @click="${this._handleClick}"
>${this.hass.localize( >${computeStateDisplay(
`state.configurator.${this.notification.state}` this.hass.localize,
this.notification,
this.hass.language
)}</mwc-button )}</mwc-button
> >
</notification-item-template> </notification-item-template>

View File

@ -165,7 +165,7 @@ class HuiAlarmPanelCard extends LitElement implements LovelaceCard {
<ha-card <ha-card
.header="${this._config.name || .header="${this._config.name ||
stateObj.attributes.friendly_name || stateObj.attributes.friendly_name ||
this._label(stateObj.state)}" this._stateDisplay(stateObj.state)}"
> >
<ha-label-badge <ha-label-badge
class="${classMap({ [stateObj.state]: true })}" class="${classMap({ [stateObj.state]: true })}"
@ -184,7 +184,7 @@ class HuiAlarmPanelCard extends LitElement implements LovelaceCard {
@click="${this._handleActionClick}" @click="${this._handleActionClick}"
outlined outlined
> >
${this._label(state)} ${this._stateDisplay(state)}
</mwc-button> </mwc-button>
`; `;
})} })}
@ -212,7 +212,9 @@ class HuiAlarmPanelCard extends LitElement implements LovelaceCard {
outlined outlined
> >
${value === "clear" ${value === "clear"
? this._label("clear_code") ? this.hass!.localize(
`ui.card.alarm_control_panel.clear_code`
)
: value} : value}
</mwc-button> </mwc-button>
`; `;
@ -232,10 +234,9 @@ class HuiAlarmPanelCard extends LitElement implements LovelaceCard {
: stateLabel; : stateLabel;
} }
private _label(state: string): string { private _stateDisplay(state: string): string {
return ( return this.hass!.localize(
this.hass!.localize(`state.alarm_control_panel.${state}`) || `component.alarm_control_panel.state._.${state}`
this.hass!.localize(`ui.card.alarm_control_panel.${state}`)
); );
} }

View File

@ -29,6 +29,7 @@ import {
} from "../types"; } from "../types";
import { HuiErrorCard } from "./hui-error-card"; import { HuiErrorCard } from "./hui-error-card";
import { EntityCardConfig } from "./types"; import { EntityCardConfig } from "./types";
import { computeStateDisplay } from "../../../common/entity/compute_state_display";
@customElement("hui-entity-card") @customElement("hui-entity-card")
export class HuiEntityCard extends LitElement implements LovelaceCard { export class HuiEntityCard extends LitElement implements LovelaceCard {
@ -128,13 +129,11 @@ export class HuiEntityCard extends LitElement implements LovelaceCard {
>${"attribute" in this._config >${"attribute" in this._config
? stateObj.attributes[this._config.attribute!] || ? stateObj.attributes[this._config.attribute!] ||
this.hass.localize("state.default.unknown") this.hass.localize("state.default.unknown")
: this.hass.localize(`state.default.${stateObj.state}`) || : computeStateDisplay(
this.hass.localize( this.hass.localize,
`state.${this._config.entity.split(".")[0]}.${ stateObj,
stateObj.state this.hass.language
}` )}</span
) ||
stateObj.state}</span
>${showUnit >${showUnit
? html` ? html`
<span class="measurement" <span class="measurement"

View File

@ -30,6 +30,7 @@ import { hasConfigOrEntityChanged } from "../common/has-changed";
import "../components/hui-warning"; import "../components/hui-warning";
import { LovelaceCard, LovelaceCardEditor } from "../types"; import { LovelaceCard, LovelaceCardEditor } from "../types";
import { LightCardConfig } from "./types"; import { LightCardConfig } from "./types";
import { computeStateDisplay } from "../../../common/entity/compute_state_display";
@customElement("hui-light-card") @customElement("hui-light-card")
export class HuiLightCard extends LitElement implements LovelaceCard { export class HuiLightCard extends LitElement implements LovelaceCard {
@ -154,8 +155,11 @@ export class HuiLightCard extends LitElement implements LovelaceCard {
${UNAVAILABLE_STATES.includes(stateObj.state) ${UNAVAILABLE_STATES.includes(stateObj.state)
? html` ? html`
<div> <div>
${this.hass.localize(`state.default.${stateObj.state}`) || ${computeStateDisplay(
stateObj.state} this.hass.localize,
stateObj,
this.hass.language
)}
</div> </div>
` `
: html` : html`

View File

@ -195,7 +195,9 @@ export class HuiThermostatCard extends LitElement implements LovelaceCard {
? this.hass!.localize( ? this.hass!.localize(
`state_attributes.climate.hvac_action.${stateObj.attributes.hvac_action}` `state_attributes.climate.hvac_action.${stateObj.attributes.hvac_action}`
) )
: this.hass!.localize(`state.climate.${stateObj.state}`) : this.hass!.localize(
`component.climate.state._.${stateObj.state}`
)
} }
${ ${
stateObj.attributes.preset_mode && stateObj.attributes.preset_mode &&

View File

@ -32,6 +32,7 @@ import {
weatherImages, weatherImages,
} from "../../../data/weather"; } from "../../../data/weather";
import { stateIcon } from "../../../common/entity/state_icon"; import { stateIcon } from "../../../common/entity/state_icon";
import { computeStateDisplay } from "../../../common/entity/compute_state_display";
const DAY_IN_MILLISECONDS = 86400000; const DAY_IN_MILLISECONDS = 86400000;
@ -185,8 +186,11 @@ class HuiWeatherForecastCard extends LitElement implements LovelaceCard {
${this._config.name || computeStateName(stateObj)} ${this._config.name || computeStateName(stateObj)}
</div> </div>
<div class="state"> <div class="state">
${this.hass.localize(`state.weather.${stateObj.state}`) || ${computeStateDisplay(
stateObj.state} this.hass.localize,
stateObj,
this.hass.language
)}
</div> </div>
</div> </div>
</div> </div>

View File

@ -20,6 +20,7 @@ import { HomeAssistant, WeatherEntity } from "../../../types";
import { EntitiesCardEntityConfig } from "../cards/types"; import { EntitiesCardEntityConfig } from "../cards/types";
import { hasConfigOrEntityChanged } from "../common/has-changed"; import { hasConfigOrEntityChanged } from "../common/has-changed";
import { LovelaceRow } from "./types"; import { LovelaceRow } from "./types";
import { computeStateDisplay } from "../../../common/entity/compute_state_display";
@customElement("hui-weather-entity-row") @customElement("hui-weather-entity-row")
class HuiWeatherEntityRow extends LitElement implements LovelaceRow { class HuiWeatherEntityRow extends LitElement implements LovelaceRow {
@ -69,8 +70,11 @@ class HuiWeatherEntityRow extends LitElement implements LovelaceRow {
<div class="attributes"> <div class="attributes">
<div> <div>
${UNAVAILABLE_STATES.includes(stateObj.state) ${UNAVAILABLE_STATES.includes(stateObj.state)
? this.hass.localize(`state.default.${stateObj.state}`) || ? computeStateDisplay(
stateObj.state this.hass.localize,
stateObj,
this.hass.language
)
: html` : html`
${stateObj.attributes.temperature} ${stateObj.attributes.temperature}
${getWeatherUnit(this.hass, "temperature")} ${getWeatherUnit(this.hass, "temperature")}

View File

@ -5,6 +5,7 @@ import { html } from "@polymer/polymer/lib/utils/html-tag";
import { PolymerElement } from "@polymer/polymer/polymer-element"; import { PolymerElement } from "@polymer/polymer/polymer-element";
import "../components/entity/state-info"; import "../components/entity/state-info";
import LocalizeMixin from "../mixins/localize-mixin"; import LocalizeMixin from "../mixins/localize-mixin";
import { computeStateDisplay } from "../common/entity/compute_state_display";
/* /*
* @appliesMixin LocalizeMixin * @appliesMixin LocalizeMixin
@ -24,7 +25,7 @@ class StateCardConfigurator extends LocalizeMixin(PolymerElement) {
<div class="horizontal justified layout"> <div class="horizontal justified layout">
${this.stateInfoTemplate} ${this.stateInfoTemplate}
<mwc-button hidden$="[[inDialog]]" <mwc-button hidden$="[[inDialog]]"
>[[_localizeState(stateObj.state)]]</mwc-button >[[_localizeState(stateObj)]]</mwc-button
> >
</div> </div>
@ -56,8 +57,12 @@ class StateCardConfigurator extends LocalizeMixin(PolymerElement) {
}; };
} }
_localizeState(state) { _localizeState(stateObj) {
return this.localize(`state.configurator.${state}`); return computeStateDisplay(
this.hass.localize,
stateObj,
this.hass.language
);
} }
} }
customElements.define("state-card-configurator", StateCardConfigurator); customElements.define("state-card-configurator", StateCardConfigurator);

View File

@ -5,6 +5,7 @@ import { PolymerElement } from "@polymer/polymer/polymer-element";
import "../components/entity/state-info"; import "../components/entity/state-info";
import LocalizeMixin from "../mixins/localize-mixin"; import LocalizeMixin from "../mixins/localize-mixin";
import HassMediaPlayerEntity from "../util/hass-media-player-model"; import HassMediaPlayerEntity from "../util/hass-media-player-model";
import { computeStateDisplay } from "../common/entity/compute_state_display";
/* /*
* @appliesMixin LocalizeMixin * @appliesMixin LocalizeMixin
@ -85,9 +86,7 @@ class StateCardMediaPlayer extends LocalizeMixin(PolymerElement) {
computePrimaryText(localize, playerObj) { computePrimaryText(localize, playerObj) {
return ( return (
playerObj.primaryTitle || playerObj.primaryTitle ||
localize(`state.media_player.${playerObj.stateObj.state}`) || computeStateDisplay(localize, playerObj.stateObj, this.hass.language)
localize(`state.default.${playerObj.stateObj.state}`) ||
playerObj.stateObj.state
); );
} }
} }