Simple translator based on local dictionary
This commit is contained in:
parent
d2fa6d8fd7
commit
710255604a
3 changed files with 109 additions and 2 deletions
|
@ -2,6 +2,7 @@ default_language = "en"
|
||||||
|
|
||||||
'''Characters following '*' are placeholders and will be replaced by some number/text/etc.'''
|
'''Characters following '*' are placeholders and will be replaced by some number/text/etc.'''
|
||||||
|
|
||||||
|
'''Events'''
|
||||||
more_events = {
|
more_events = {
|
||||||
'en' : '+ *0 more',
|
'en' : '+ *0 more',
|
||||||
'de' : '+ *0 weitere'
|
'de' : '+ *0 weitere'
|
||||||
|
@ -14,3 +15,85 @@ allday_events = {
|
||||||
'en' : 'All-day',
|
'en' : 'All-day',
|
||||||
'de' : 'Ganztägig'
|
'de' : 'Ganztägig'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
'''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
|
||||||
|
]
|
|
@ -3,6 +3,7 @@ from WeatherInterface import WeatherInterface
|
||||||
import pyowm
|
import pyowm
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from settings import units, language
|
from settings import units, language
|
||||||
|
from Translator import translate
|
||||||
|
|
||||||
class OwmForecasts (WeatherInterface):
|
class OwmForecasts (WeatherInterface):
|
||||||
"""Fetches weather through the Openweathermap-api."""
|
"""Fetches weather through the Openweathermap-api."""
|
||||||
|
@ -62,7 +63,7 @@ class OwmForecasts (WeatherInterface):
|
||||||
forecast_object.icon = weather.get_weather_icon_name()
|
forecast_object.icon = weather.get_weather_icon_name()
|
||||||
forecast_object.air_humidity = str(weather.get_humidity())
|
forecast_object.air_humidity = str(weather.get_humidity())
|
||||||
forecast_object.clouds = str(weather.get_clouds())
|
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.detailed_description = str(weather.get_detailed_status())
|
||||||
forecast_object.air_pressure = str(weather.get_pressure()['press'])
|
forecast_object.air_pressure = str(weather.get_pressure()['press'])
|
||||||
|
|
||||||
|
|
23
Calendar/Translator.py
Normal file
23
Calendar/Translator.py
Normal file
|
@ -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
|
Loading…
Reference in a new issue