Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

computeStateDisplay does not utilize translation_key #290

Closed
mill1000 opened this issue Apr 11, 2023 · 3 comments
Closed

computeStateDisplay does not utilize translation_key #290

mill1000 opened this issue Apr 11, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@mill1000
Copy link
Contributor

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
  );
@rtasarz
Copy link

rtasarz commented Apr 18, 2023

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.

@mill1000
Copy link
Contributor Author

I made a PR as well. #293

@benct benct added the bug Something isn't working label Apr 18, 2023
@mill1000
Copy link
Contributor Author

Closed via #293

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants