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

Add translations for entity names #1411

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

caibinqing
Copy link
Contributor

Here gives a simplest modification,
It can solve the translation problems of most commonly used entities.

have tested on HA 2023.7 and 2024.7

related issue: #1405

@AlexxIT AlexxIT self-assigned this Jul 28, 2024
@caibinqing
Copy link
Contributor Author

Not so good, names like ble mesh zigbee should be kept.

@caibinqing
Copy link
Contributor Author

Reduced coverage of the if, this version should not incorrectly translate too many entities.

The complete translation I think still needs to mark each attr separately, for main feature (name=None), or use translation_key, or use default device class translation.

@caibinqing caibinqing marked this pull request as ready for review August 12, 2024 12:36
@caibinqing caibinqing closed this Nov 1, 2024
@caibinqing caibinqing deleted the translation branch November 1, 2024 07:52
@AlexxIT
Copy link
Owner

AlexxIT commented Nov 1, 2024

Why you have closed this? Bad solution?

@caibinqing caibinqing restored the translation branch November 1, 2024 10:07
@caibinqing
Copy link
Contributor Author

Sorry, accidentally deleted the branch.
The simple if is not very good yet, I want to re-implement it, based on the idea mentioned above. What do you think?

@caibinqing caibinqing reopened this Nov 1, 2024
@caibinqing caibinqing marked this pull request as draft November 1, 2024 10:09
@AlexxIT
Copy link
Owner

AlexxIT commented Nov 1, 2024

I haven't check it yet. I don't understand how translations work in Hass at all. It's complicated.

@caibinqing
Copy link
Contributor Author

caibinqing commented Nov 1, 2024

Done, please take a look.

Entity naming will be decided in the following order:

  1. set "name": None: for entity which is the main feature of a device, name would be same as device name.
  2. set "translation_key": <some string>: use translations in translations/language.json
  3. if entity._default_to_device_class_name() returns Ture, it would be named by its device class.
  4. use previous behavior: attr.replace("_", " ").title().

For feature entity translation placeholders, HA 2024.2 is required

@caibinqing caibinqing marked this pull request as ready for review November 1, 2024 16:32
@caibinqing caibinqing changed the title Use default translations for entities that can be named by its device class Add translations for entity names Nov 1, 2024
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

Successfully merging this pull request may close these issues.

2 participants