Start adding multiple languages

This commit is contained in:
Jules 2023-12-28 22:35:41 +01:00
parent b6e3482bf6
commit cd48705c1b
Signed by: jdejaegh
GPG key ID: 99D6D184CA66933A
5 changed files with 41 additions and 4 deletions

View file

@ -33,6 +33,7 @@ class IrmKmiConfigFlow(ConfigFlow, domain=DOMAIN):
return self.async_show_form( return self.async_show_form(
step_id="user", step_id="user",
data_schema=vol.Schema({ data_schema=vol.Schema({
vol.Required(CONF_ZONE): EntitySelector(EntitySelectorConfig(domain=ZONE_DOMAIN)), vol.Required(CONF_ZONE, description="Zone to use for weather forecast"):
EntitySelector(EntitySelectorConfig(domain=ZONE_DOMAIN)),
}) })
) )

View file

@ -19,6 +19,7 @@ OUT_OF_BENELUX = ["außerhalb der Benelux (Brussels)",
"Hors de Belgique (Bxl)", "Hors de Belgique (Bxl)",
"Outside the Benelux (Brussels)", "Outside the Benelux (Brussels)",
"Buiten de Benelux (Brussel)"] "Buiten de Benelux (Brussel)"]
LANGS = ['en', 'fr', 'nl', 'de']
# map ('ww', 'dayNight') tuple from IRM KMI to HA conditions # map ('ww', 'dayNight') tuple from IRM KMI to HA conditions
IRM_KMI_TO_HA_CONDITION_MAP = { IRM_KMI_TO_HA_CONDITION_MAP = {

View file

@ -17,7 +17,7 @@ from homeassistant.helpers.update_coordinator import (DataUpdateCoordinator,
from PIL import Image, ImageDraw, ImageFont from PIL import Image, ImageDraw, ImageFont
from .api import IrmKmiApiClient, IrmKmiApiError from .api import IrmKmiApiClient, IrmKmiApiError
from .const import IRM_KMI_TO_HA_CONDITION_MAP as CDT_MAP from .const import IRM_KMI_TO_HA_CONDITION_MAP as CDT_MAP, LANGS
from .const import OUT_OF_BENELUX from .const import OUT_OF_BENELUX
from .data import (AnimationFrameData, CurrentWeatherData, IrmKmiForecast, from .data import (AnimationFrameData, CurrentWeatherData, IrmKmiForecast,
ProcessedCoordinatorData, RadarAnimationData) ProcessedCoordinatorData, RadarAnimationData)
@ -88,8 +88,9 @@ class IrmKmiCoordinator(DataUpdateCoordinator):
images_from_api = images_from_api[1:] images_from_api = images_from_api[1:]
radar_animation = await self.merge_frames_from_api(animation_data, country, images_from_api, localisation) radar_animation = await self.merge_frames_from_api(animation_data, country, images_from_api, localisation)
# TODO support translation here
radar_animation['hint'] = api_data.get('animation', {}).get('sequenceHint', {}).get('en') lang = self.hass.config.language if self.hass.config.language in LANGS else 'en'
radar_animation['hint'] = api_data.get('animation', {}).get('sequenceHint', {}).get(lang)
return radar_animation return radar_animation
async def process_api_data(self, api_data: dict) -> ProcessedCoordinatorData: async def process_api_data(self, api_data: dict) -> ProcessedCoordinatorData:

View file

@ -0,0 +1,17 @@
{
"title": "Royal Meteorological Institute of Belgium",
"config": {
"step": {
"user": {
"title": "Select a zone",
"data" : {
"zone": "Zone"
}
}
},
"abort": {
"already_configured": "Weather for this zone is already configured",
"unknown": "Unknown error occurred"
}
}
}

View file

@ -0,0 +1,17 @@
{
"title": "Institut royal météorologique de Belgique",
"config": {
"step": {
"user": {
"title": "Choisissez une zone",
"data" : {
"zone": "Zone"
}
}
},
"abort": {
"already_configured": "La météo pour cette zone est déjà configurée",
"unknown": "Une erreur inconnue est survenue"
}
}
}