thomasloven / lovelace-template-entity-row

🔹 Display whatever you want in an entities card row.
MIT License
210 stars 16 forks source link

Localization: the "_(key)" is processed for "evaluated" templates #83

Closed ildar170975 closed 1 year ago

ildar170975 commented 1 year ago

Also described here: https://community.home-assistant.io/t/template-entity-row-put-templates-in-an-entities-row/160167/81?u=ildar_gabdullin

Consider this example:

  - type: custom:template-entity-row
    entity: sun.sun
    state: >-
      {% set VALUE = states(config.entity) -%}
      {%- set LOCALIZED_VALUE = '_(component.sun.state._.'+ VALUE + ')' -%}
      {{LOCALIZED_VALUE}}

изображение

Now try this:

    state: >-
      {% set VALUE = states(config.entity) -%}
      {%- set LOCALIZED_VALUE = '_(component.sun.state._.'+ VALUE + ')' -%}
      {{LOCALIZED_VALUE | upper }}

изображение

Seems that "_(key)" cannot be processed along with other templating and is mainly not supposed to be used INSIDE a template:

state: >-
  _(component.sun.state._.{{states(config.entity)}})

Not sure if t is a bug or a FR.

thomasloven commented 1 year ago

That's just how it works.

The template itself is processed and evaluated in the backend, i.e. on the machine running Home Assistant. Then the result is sent to the frontend, i.e. your browser, which does the translations.

The browser doesn't have all the state information and processing tools required to evaluate the templates, and the backend doesn't know what language your browser is set to. Therefore your proposed feature cannot be implemented without ping-ponging the template back and forth repeatedly, which could grow infinitely complex.

ildar170975 commented 1 year ago

The template itself is processed and evaluated in the backend, i.e. on the machine running Home Assistant. Then the result is sent to the frontend, i.e. your browser, which does the translations.

This really explains the issue. Thank you, Thomas.