2019-05-09 17:41:34 +02:00
|
|
|
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) :
|
2019-05-10 08:19:22 +02:00
|
|
|
dictionary = find_dictionary(phrase, dictionary_collection)
|
2019-05-09 17:41:34 +02:00
|
|
|
|
|
|
|
if dictionary == None:
|
|
|
|
return phrase
|
|
|
|
|
|
|
|
if target_lang in dictionary.keys():
|
|
|
|
return dictionary[target_lang]
|
2019-05-10 08:11:13 +02:00
|
|
|
elif '_' in target_lang and target_lang.split('_')[0] in dictionary.keys():
|
|
|
|
return dictionary[target_lang.split('_')[0]]
|
2019-05-09 17:41:34 +02:00
|
|
|
else:
|
|
|
|
return dictionary[default_language]
|
|
|
|
|
2019-05-10 08:19:22 +02:00
|
|
|
def find_dictionary(phrase, dictionary_collection = dictionary_collection):
|
2019-05-09 17:41:34 +02:00
|
|
|
for dictionary in dictionary_collection:
|
|
|
|
if phrase in dictionary.values():
|
|
|
|
return dictionary
|
|
|
|
return None
|