Adjust backend translations for entity components (#15820)

Co-authored-by: Bram Kragten <mail@bramkragten.nl>
This commit is contained in:
Franck Nijhof
2023-03-16 13:51:38 +01:00
committed by GitHub
parent 77dcace95e
commit 0158d7e3e5
10 changed files with 37 additions and 16 deletions

View File

@@ -12,6 +12,7 @@ export const computeAttributeValueDisplay = (
value?: any
): string => {
const entityId = stateObj.entity_id;
const deviceClass = stateObj.attributes.device_class;
const attributeValue =
value !== undefined ? value : stateObj.attributes[attribute];
const domain = computeDomain(entityId);
@@ -23,8 +24,12 @@ export const computeAttributeValueDisplay = (
localize(
`component.${entity.platform}.entity.${domain}.${translationKey}.state_attributes.${attribute}.state.${attributeValue}`
)) ||
(deviceClass &&
localize(
`component.${domain}.entity_component.${deviceClass}.state_attributes.${attribute}.state.${attributeValue}`
)) ||
localize(
`component.${domain}.state_attributes._.${attribute}.state.${attributeValue}`
`component.${domain}.entity_component._.state_attributes.${attribute}.state.${attributeValue}`
) ||
attributeValue
);
@@ -37,6 +42,7 @@ export const computeAttributeNameDisplay = (
attribute: string
): string => {
const entityId = stateObj.entity_id;
const deviceClass = stateObj.attributes.device_class;
const domain = computeDomain(entityId);
const entity = entities[entityId] as EntityRegistryDisplayEntry | undefined;
const translationKey = entity?.translation_key;
@@ -46,7 +52,13 @@ export const computeAttributeNameDisplay = (
localize(
`component.${entity.platform}.entity.${domain}.${translationKey}.state_attributes.${attribute}.name`
)) ||
localize(`component.${domain}.state_attributes._.${attribute}.name`) ||
(deviceClass &&
localize(
`component.${domain}.entity_component.${deviceClass}.state_attributes.${attribute}.name`
)) ||
localize(
`component.${domain}.entity_component._.state_attributes.${attribute}.name`
) ||
attribute
);
};