I have an “options_flow.py” file to manage changes in the setup of a custom integrations.
The code for the “options_flow.py” looks as follows:
class MeteocatOptionsFlowHandler(OptionsFlow):
"""Manejo del flujo de opciones para Meteocat."""
def __init__(self, config_entry: ConfigEntry):
"""Inicializa el flujo de opciones."""
self._config_entry = config_entry
self.api_key: str | None = None
self.limit_xema: int | None = None
self.limit_prediccio: int | None = None
async def async_step_init(self, user_input: dict | None = None):
"""Paso inicial del flujo de opciones."""
if user_input is not None:
if user_input["option"] == "update_api_and_limits":
return await self.async_step_update_api_and_limits()
elif user_input["option"] == "update_limits_only":
return await self.async_step_update_limits_only()
return self.async_show_form(
step_id="init",
data_schema=vol.Schema({
vol.Required("option"): vol.In({
"update_api_and_limits": "Update API Key and limits.",
"update_limits_only": "Update API limits."
})
})
)
I am trying to setup the strings.json to translate “update_api_and_limits” adn “update_limits_only” from:
vol.In({
"update_api_and_limits": "Update API Key and limits.",
"update_limits_only": "Update API limits."
})
In order to achive the translation to other languages, es.json, ca.json, … I tried to change the code following the Developer Docs (Developers Docs - Selectors):
from homeassistant.helpers.selector import SelectSelector, SelectSelectorConfig
return self.async_show_form(
step_id="init",
data_schema=vol.Schema({
vol.Required("option"): SelectSelector(
SelectSelectorConfig(
options=[
"update_api_and_limits",
"update_limits_only"
],
translation_key="selector.options"
)
)
})
)
And the strings.json, en.json, es.json, looks as follows:
{
"options": {
"step":{
"init": {
"description": "Setup the API Key and the limits for XEMA and PREDICTIONS.",
"title": "Setup options.",
"data": {
"option": "Options"
}
},
"update_api_and_limits": {
"description": "Setup the API Key and the limits for XEMA and PREDICTIONS.",
"title": "API Key and limits."
},
"update_limits_only": {
"description": "Setup the limits for XEMA and PREDICTIONS.",
"title": "API limits."
}
},
"selector": {
"options": {
"update_api_and_limits": "Update API Key and limits.",
"update_limits_only": "Update API limits."
}
},
"error": {
"cannot_connect": "Cannot connect. Error when checking the new API Key.",
"unknown": "Unknown error when checking the new API Key.",
"invalid_limit": "Invalid limit. The limit must be a positive number."
}
}
}
But this solution is not working. Any idea?