Skip to content

Commit

Permalink
Start adding multiple languages
Browse files Browse the repository at this point in the history
  • Loading branch information
jdejaegh committed Dec 28, 2023
1 parent b6e3482 commit cd48705
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 4 deletions.
3 changes: 2 additions & 1 deletion custom_components/irm_kmi/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ async def async_step_user(self, user_input: dict | None = None) -> FlowResult:
return self.async_show_form(
step_id="user",
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)),
})
)
1 change: 1 addition & 0 deletions custom_components/irm_kmi/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"Hors de Belgique (Bxl)",
"Outside the Benelux (Brussels)",
"Buiten de Benelux (Brussel)"]
LANGS = ['en', 'fr', 'nl', 'de']

# map ('ww', 'dayNight') tuple from IRM KMI to HA conditions
IRM_KMI_TO_HA_CONDITION_MAP = {
Expand Down
7 changes: 4 additions & 3 deletions custom_components/irm_kmi/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from PIL import Image, ImageDraw, ImageFont

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 .data import (AnimationFrameData, CurrentWeatherData, IrmKmiForecast,
ProcessedCoordinatorData, RadarAnimationData)
Expand Down Expand Up @@ -88,8 +88,9 @@ async def _async_animation_data(self, api_data: dict) -> RadarAnimationData:
images_from_api = images_from_api[1:]

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

async def process_api_data(self, api_data: dict) -> ProcessedCoordinatorData:
Expand Down
17 changes: 17 additions & 0 deletions custom_components/irm_kmi/translations/en.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
17 changes: 17 additions & 0 deletions custom_components/irm_kmi/translations/fr.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}

0 comments on commit cd48705

Please sign in to comment.