Frontend translation files in script/value_template?

{{ states.weather.smhi_home.attributes.forecast[1].condition }} gives sunny
Can it be translated to other languages in a value_template?
In the translation file there is :

            "weather": {
            "clear-night": "Klart, natt",
            "cloudy": "Molnigt",
            "exceptional": "Exceptionellt",
            "fog": "Dimma",
            "hail": "Hagel",
            "lightning": "Åska",
            "lightning-rainy": "Åska, regnigt",
            "partlycloudy": "Delvis molnigt",
            "pouring": "Ösregn",
            "rainy": "Regnigt",
            "snowy": "Snöigt",
            "snowy-rainy": "Snöigt, regnigt",
            "sunny": "Soligt",
            "windy": "Blåsigt",
            "windy-variant": "Blåsigt"
        }

/Conny

1 Like

OK, found a fugly workaround:

{% set condition = (states.weather.smhi_home.attributes.forecast[1].condition) %}
{% set conditions = {'clear-night': 'klart, natt', 'cloudy': 'molnigt', 'exceptional': 'exceptionellt', 'fog': 'dimma', 'hail': 'hagel', 'lightning': 'åska', 'lightning-rainy': 'åska, regnigt', 'partlycloudy': 'delvis molnigt', 'pouring': 'ösregn', 'rainy': 'regnigt', 'snowy': 'snöigt', 'snowy-rainy': 'snöigt, regnigt', 'sunny': 'soligt', 'windy': 'blåsigt', 'windy-variant': 'blåsigt'} %}
{{ conditions[condition] }}

This will “translate” the forecast condition to swedish…

1 Like

Thanks for sharing your approach. I’d like to share some German translations here as well - as full sentences, e.g. for voice announcements.:

{
    "clear-night": "Es ist eine klare Nacht",
    "cloudy":"Es ist bewölkt",
    "exceptional":"Es herrscht außergewöhnliches Wetter",
    "fog":"Es ist neblig",
    "hail":"Es hagelt",
    "lightning":"Es gewittert",
    "lightning-rainy":"Es regnet und gewittert",
    "partlycloudy":"Es ist teilweise bewölkt",
    "pouring":"Es regnet in Strömen",
    "rainy":"Es ist regnerisch",
    "snowy":"Es schneit",
    "snowy-rainy":"Es regnet und schneit",
    "sunny":"Es ist sonnig",
    "windy":"Es ist windig",
    "windy-variant":"Es ist windig und bewölkt",
}
1 Like