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

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

Closed
ildar170975 opened this issue Aug 5, 2022 · 2 comments
Closed

Comments

@ildar170975
Copy link

ildar170975 commented Aug 5, 2022

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
Copy link
Owner

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
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants