-
Notifications
You must be signed in to change notification settings - Fork 8
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
Translation possible? #30
Comments
Value Translation is possible, but a lot of work. Entity renaming is also possible but won't work with our current dynamic prefix system. I will work on the values first. |
Adding translation possibility of all names and values will be part of a new version. Inbeteween you can help yourself as follows:
|
Thanks a lot for the feedback! With the help of some AI, I've translated the file in Dutch. Please find attached the translated file. After changing this file and restarting HA, the integration created completely new entities (and thus entity_ids) causing the few automations I had build to break. May I suggest to keep this in mind when developing this translation feature? I assume this translation feature will result in a rather large refactor, so another suggestion I would like to make is the possibility to define icons in the hpconst.py file. |
For the next version, we can include entity names and states as described here: https://developers.home-assistant.io/docs/internationalization/core But we have to look how to handle pre and postfixes.. |
Im already working on the translation feature. It will NOT change the "unique id" witch HA take for statistics and translate the name. But we have to put EVERY sensor in a json like this: As you can imagine this is verry time consuming, so please be patient. |
@StijnVdd thanks for the file. I hope that the entity IDs will preserve when using the method described in the link in my last post. (It‘s my 1st integration, have to learn a lot..) |
A kind of coincidence ;-) |
@OStrama : |
Maybe, it‘s faster to write a little python script that crunches through the ModbusItem and StatusItem lists and builds the json file automatically ;-) |
Can you read my mind? Scary ;) |
I have a version we can test. But can't push from here in work. Will Push when i am at home. Prefix should work with {placeholder} |
Once pushed, I'll give it a try. Looking forward to it |
@StijnVdd : No build to test for you yet. Still working on it, sorry. @OStrama: I made a generation function in init.py. We have to copy strings manually by now. I am working on a automatical generation of strings.json and the {place_holder} now. |
@OStrama : I finally finished the translation system. Can you please also check if it is working as expected? |
I tested the files that were checked in. To see what happens, I translated some of the entities in en.json into English. The entity names seem to be translated. However, the name of the selections of a select entity do not change:
I checked out "translation" |
Maybe, it also would make sense to add translations to the devices, like this:
|
Another point. If I look at:
And the usage of the name, it looks as if the name of the modbus item itself is not longer used. Shouldn't we completely replace it by the translation key or generate one of them automatically? Or do you need both to cretae strins.json? |
|
At the moment i use the name to gereate the strings.json. When the translation system is complete, we can erase the names. |
I found a way also to translate the list entries.. |
Please push it. |
done ;-) |
it was basically using translation_key as strings here, too.. |
I was on a similar path, but changed the text_from_number function whitch seems to break something else. This looks good to me. So only the devices are missing and perhaps the prefix system |
text_from_number is also used to get text of error messages etc. When we put all in translation system, we could get rid of one of them.. |
You have to be carefull with your translation_key values: Error: R] [TRANSLATIONS] Invalid strings.json: Invalid translation key 'System', need to be [a-z0-9-_]+ and cannot start or end with a hyphen or underscore. for dictionary value @ data['device']. Got {'System': {'name': 'System'}, 'Wärmepumpe': {'name': 'Heat pump'}, 'Warmwasser': {'name': 'Hot water'}, 'Heizkreis': {'name': 'Heating circuit'}, 'Heizkreis2': {'name': 'Heating circuit2'}, 'Heizkreis3': {'name': 'Heating circuit3'}, 'Heizkreis4': {'name': 'Heating circuit4'}, 'Heizkreis5': {'name': 'Heating circuit5'}, '2. Wärmeerzeuger': {'name': '2nd heat source'}, 'Statistik': {'name': 'Statistics'}, 'Unknown': {'name': 'Unknown'}, 'Eingänge/Ausgänge': {'name': 'Input/output'}} The hacs check complains: Invalid translation key 'System', need to be [a-z0-9-_]+ and cannot start or end with a hyphen or underscore. This is why i had to recreate the translation_key. Before i had just copied the name over. But his HACS check won't allow that. Thats the reason why you probably got 20 emails ;) |
But entities stay as they are, so we could use this.. |
done ;-) |
I completely translated en.json. @StijnVdd : What about adding a file nl.json ;-) |
@MadOne What do you think, should we try to merge back translation to main? |
Not sure if we should fix the prefix system first. |
Ah yes, makes sense. I saw on some source codes in core constructs like this: "config": { I do not really understand the syntax, but it seems that there's a way to use variables in names. Otherwise, we have to find out what method of the entity class does the translation and overwrite it.. |
As far as i know this are official home assistant strings. |
Or shared strings: |
... or the brute-force method: Overwriting _device_class_name_helper() in SensorEntity and thwe others ;-)
|
Looks a bit hacky to me. I think i got it with this: |
OK, then delete the helper function to avoid interference.. |
I have no working solution yet but this looks very promising. But its good to have a backup strategy. Could you please look at this? |
I somehow messed up the merge and now the translation of the sensor values and dropdowns is again not working. Can you have a look at it? |
Yes, sure! |
I think you should delete this function in entities.py
Then maybe the reverse_device_list was changed and could cause an issue.. |
Translation will be possible in the next release. |
Hi, I just downloaded the most recent version of the integration. |
Hi, We did not aktivate the translation yet, due to an entity naming issue. Anyways you can already start translaing. |
I'll translate the strings.json to dutch. Is it correct the entity ID will always be in German and the 'translation' changes just the name? |
Strings.json is used as default when translation is enabled, but it is NOT at the moment. As far as i have in mind the entity id says the same and only the friendly name changes. But can not test / confirm that right now. |
Thanks for you fast reply ! Is there a way for me to 'enable' the translations for now so I can play around with it ? |
I created a new release UNSTABLE_1.0.2_Translation_UNSTABLE. Be aware, this can create new devices and entitys, thus create new sensor history. |
Thanks a lot. I installed this version and replaced the strings.json with my own version (dutch). I also added the nl.json in the translation folder but the integration is not picking up my file. I do notice the entity IDs changes to english an no longer are in german. I'll test a bit more and provide more feedback. How is the language selected? |
Leave string.json and place your files in the translation folder. Language is taken from your home assistant. You may need to restart ha for change of language |
Hi, please use version 1.0.4pre. In this version translation is enabled. |
Hi,
First of all, thanks a lot for this integration!
Would it be possible to provide a translation for all the entities and their state ?
I've been renaming the entity names in HA and this mostly does meet my requirement, but the states of the entities are not changeable (at least not without defining a template entity or something like that)
I would therefore like to suggest the possibility to configure the language of integration. For example via a setting or by using the same language as the HA frontend.
I would love to help out with the translation files.
Thanks a lot the the consideration.
The text was updated successfully, but these errors were encountered: