Add back blank before percent sign ("%") based on language (#13590)

Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
This commit is contained in:
Philip Allgaier 2022-09-05 14:49:21 +02:00 committed by GitHub
parent ab745f6e8e
commit a817faae54
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 5 deletions

View File

@ -2,17 +2,18 @@ import { HassEntity } from "home-assistant-js-websocket";
import { UNAVAILABLE, UNKNOWN } from "../../data/entity"; import { UNAVAILABLE, UNKNOWN } from "../../data/entity";
import { FrontendLocaleData } from "../../data/translation"; import { FrontendLocaleData } from "../../data/translation";
import { import {
UPDATE_SUPPORT_PROGRESS,
updateIsInstallingFromAttributes, updateIsInstallingFromAttributes,
UPDATE_SUPPORT_PROGRESS,
} from "../../data/update"; } from "../../data/update";
import { formatDuration, UNIT_TO_SECOND_CONVERT } from "../datetime/duration";
import { formatDate } from "../datetime/format_date"; import { formatDate } from "../datetime/format_date";
import { formatDateTime } from "../datetime/format_date_time"; import { formatDateTime } from "../datetime/format_date_time";
import { formatTime } from "../datetime/format_time"; import { formatTime } from "../datetime/format_time";
import { formatNumber, isNumericFromAttributes } from "../number/format_number"; import { formatNumber, isNumericFromAttributes } from "../number/format_number";
import { blankBeforePercent } from "../translations/blank_before_percent";
import { LocalizeFunc } from "../translations/localize"; import { LocalizeFunc } from "../translations/localize";
import { supportsFeatureFromAttributes } from "./supports-feature";
import { formatDuration, UNIT_TO_SECOND_CONVERT } from "../datetime/duration";
import { computeDomain } from "./compute_domain"; import { computeDomain } from "./compute_domain";
import { supportsFeatureFromAttributes } from "./supports-feature";
export const computeStateDisplay = ( export const computeStateDisplay = (
localize: LocalizeFunc, localize: LocalizeFunc,
@ -67,7 +68,7 @@ export const computeStateDisplayFromEntityAttributes = (
const unit = !attributes.unit_of_measurement const unit = !attributes.unit_of_measurement
? "" ? ""
: attributes.unit_of_measurement === "%" : attributes.unit_of_measurement === "%"
? "%" ? blankBeforePercent(locale) + "%"
: ` ${attributes.unit_of_measurement}`; : ` ${attributes.unit_of_measurement}`;
return `${formatNumber(state, locale)}${unit}`; return `${formatNumber(state, locale)}${unit}`;
} }

View File

@ -0,0 +1,18 @@
import { FrontendLocaleData } from "../../data/translation";
// Logic based on https://en.wikipedia.org/wiki/Percent_sign#Form_and_spacing
export const blankBeforePercent = (
localeOptions: FrontendLocaleData
): string => {
switch (localeOptions.language) {
case "cz":
case "de":
case "fi":
case "fr":
case "sk":
case "sv":
return " ";
default:
return "";
}
};

View File

@ -2,6 +2,7 @@ import { css, LitElement, PropertyValues, svg, TemplateResult } from "lit";
import { customElement, property, state } from "lit/decorators"; import { customElement, property, state } from "lit/decorators";
import { styleMap } from "lit/directives/style-map"; import { styleMap } from "lit/directives/style-map";
import { formatNumber } from "../common/number/format_number"; import { formatNumber } from "../common/number/format_number";
import { blankBeforePercent } from "../common/translations/blank_before_percent";
import { afterNextRender } from "../common/util/render-status"; import { afterNextRender } from "../common/util/render-status";
import { FrontendLocaleData } from "../data/translation"; import { FrontendLocaleData } from "../data/translation";
import { getValueInPercentage, normalize } from "../util/calculate"; import { getValueInPercentage, normalize } from "../util/calculate";
@ -133,7 +134,11 @@ export class Gauge extends LitElement {
? this._segment_label ? this._segment_label
: this.valueText || formatNumber(this.value, this.locale) : this.valueText || formatNumber(this.value, this.locale)
}${ }${
this._segment_label ? "" : this.label === "%" ? "%" : ` ${this.label}` this._segment_label
? ""
: this.label === "%"
? blankBeforePercent(this.locale) + "%"
: ` ${this.label}`
} }
</text> </text>
</svg>`; </svg>`;