benct / lovelace-multiple-entity-row

Show multiple entity states and attributes on entity rows in Home Assistant's Lovelace UI

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

computeStateDisplay does not utilize translation_key

mill1000 opened this issue · comments

The current implementation of computeStateDisplay does not utilize an entity's translation_key which can result in unlocalized states.
e.g.
As of Core 2023.4.0, The transmission status sensor is capitalized when used in Entities, but not in multiple-entity-row
image

The current implementation:

return (
// Return device class translation
(stateObj.attributes.device_class &&
localize(`component.${domain}.state.${stateObj.attributes.device_class}.${compareState}`)) ||
// Return default translation
localize(`component.${domain}.state._.${compareState}`) ||
// We don't know! Return the raw state.
compareState
);

Possible correct implementation from the frontend.

return (
    (entity?.translation_key &&
      localize(
        `component.${entity.platform}.entity.${domain}.${entity.translation_key}.state.${state}`
      )) ||
    // Return device class translation
    (attributes.device_class &&
      localize(
        `component.${domain}.entity_component.${attributes.device_class}.state.${state}`
      )) ||
    // Return default translation
    localize(`component.${domain}.entity_component._.state.${state}`) ||
    // We don't know! Return the raw state.
    state
  );

After some tweaking replacement code indeed works. I have committed changes to my fork, but I need to find some time to check if adapted entity?.translation_key condition is changed correctly before preparing pull request.

I made a PR as well. #293

Closed via #293