Multilanguage support with Google Assistant
Checklist
- [x] I checked for similar existing requests (both open and closed) before posting.
- [x] My request is generic, other users may benefit from it too.
Proposal
Google assistant integration in Home Assistant doesn't support multi language, it is hard coded in english :
for state in self._supported_states():
# level synonyms are generated from state names
# 'armed_away' becomes 'armed away' or 'away'
level_synonym = [state.replace("_", " ")]
if state != STATE_ALARM_TRIGGERED:
level_synonym.append(state.split("_")[1])
level = {
"level_name": state,
"level_values": [{"level_synonym": level_synonym, "lang": "en"}],
}
levels.append(level)
I would like to add support for multi language. Alarmo only provide en.json file, so I made a fr.json file in the translation folder.
However, it doesn't cover attributes translation (only the services we can use from automation), and so the usual local translation functions doesn't work. I do not have the knowledge to add such functionnality. But I think it is related to: https://developers.home-assistant.io/docs/internationalization/core/#entity-state-attributes
Additional info
Bascilly, I need to retrieve the "language value" for each of the possible arming level.
def sync_attributes(self):
"""Return ArmDisarm attributes for a sync request."""
response = {}
levels = []
for state in self._supported_states():
if state == STATE_ALARM_ARMED_HOME:
level = {
"level_name": state,
"level_values": [{"level_synonym": ["Présent"], "lang": "fr"}],
}
levels.append(level)
See above, all I need is to retrieve the language for each supported state. It could also be all the language for each state, like : "level_values": [{"level_synonym": ["Présent"], "lang": "fr"}, {"level_synonym": ["Home"], "lang": en"}],
Remark: I found the state_translated funtion, but nowhere a state_attr_translated function, so I'm unsure how to retrieve all the translation of a state's attribute.