diff --git a/Calendar/Dictionary.py b/Calendar/Dictionary.py index 9b18dfb..327f563 100644 --- a/Calendar/Dictionary.py +++ b/Calendar/Dictionary.py @@ -2,6 +2,7 @@ default_language = "en" '''Characters following '*' are placeholders and will be replaced by some number/text/etc.''' +'''Events''' more_events = { 'en' : '+ *0 more', 'de' : '+ *0 weitere' @@ -13,4 +14,86 @@ multiday_events = { allday_events = { 'en' : 'All-day', 'de' : 'Ganztägig' -} \ No newline at end of file +} + +'''Weather''' +rain_weather = { + 'en' : 'Rain', + 'de' : 'Regen' +} +clear_weather = { + 'en' : 'Clear', + 'de' : 'Klar' +} +clouds_weather = { + 'en' : 'Clouds', + 'de' : 'Wolken' +} +thunderstorm_weather = { + 'en' : 'Thunderstorm', + 'de' : 'Gewitter' +} +drizzle_weather = { + 'en' : 'Drizzle', + 'de' : 'Niesel' +} +snow_weather = { + 'en' : 'Snow', + 'de' : 'Schnee' +} +mist_weather = { + 'en' : 'Mist', + 'de' : 'Nebel' +} +smoke_weather = { + 'en' : 'Smoke', + 'de' : 'Rauch' +} +haze_weather = { + 'en' : 'Haze', + 'de' : 'Nebel' +} +dust_weather = { + 'en' : 'Dust', + 'de' : 'Staub' +} +fog_weather = { + 'en' : 'Fog', + 'de' : 'Nebel' +} +sand_weather = { + 'en' : 'Sand', + 'de' : 'Sand' +} +ash_weather = { + 'en' : 'Ash', + 'de' : 'Asche' +} +squall_weather = { + 'en' : 'Squall', + 'de' : 'Sturm' +} +tornado_weather = { + 'en' : 'Tornado', + 'de' : 'Tornado' +} +dictionary_collection = [ + rain_weather, + clear_weather, + dust_weather, + squall_weather, + tornado_weather, + clouds_weather, + thunderstorm_weather, + smoke_weather, + ash_weather, + sand_weather, + fog_weather, + haze_weather, + mist_weather, + drizzle_weather, + snow_weather, + more_events, + allday_events, + multiday_events +] \ No newline at end of file diff --git a/Calendar/OwmForecasts.py b/Calendar/OwmForecasts.py index fd2554c..adbb45c 100644 --- a/Calendar/OwmForecasts.py +++ b/Calendar/OwmForecasts.py @@ -3,6 +3,7 @@ from WeatherInterface import WeatherInterface import pyowm from datetime import datetime from settings import units, language +from Translator import translate class OwmForecasts (WeatherInterface): """Fetches weather through the Openweathermap-api.""" @@ -62,7 +63,7 @@ class OwmForecasts (WeatherInterface): forecast_object.icon = weather.get_weather_icon_name() forecast_object.air_humidity = str(weather.get_humidity()) forecast_object.clouds = str(weather.get_clouds()) - forecast_object.short_description = str(weather.get_status()) + forecast_object.short_description = translate(str(weather.get_status())) forecast_object.detailed_description = str(weather.get_detailed_status()) forecast_object.air_pressure = str(weather.get_pressure()['press']) diff --git a/Calendar/Translator.py b/Calendar/Translator.py new file mode 100644 index 0000000..218a6a0 --- /dev/null +++ b/Calendar/Translator.py @@ -0,0 +1,23 @@ +from Dictionary import default_language, dictionary_collection +from settings import language + +'''Looks up a phrase in a given dictionary-collection +and returns the translated phrase''' + +def translate(phrase, target_lang = language, dictionary_collection = dictionary_collection) : + dictionary = find_dictionary(dictionary_collection, phrase) + + if dictionary == None: + return phrase + + if target_lang in dictionary.keys(): + return dictionary[target_lang] + else: + return dictionary[default_language] + + +def find_dictionary(dictionary_collection, phrase): + for dictionary in dictionary_collection: + if phrase in dictionary.values(): + return dictionary + return None \ No newline at end of file