E-Paper-Calendar/Calendar/DictionaryMapper.py

30 lines
866 B
Python
Raw Normal View History

from Dictionary import default_language
from settings import language
'''Takes a collection of phrases and outputs the necessary text
according to the language and inserts parameters.'''
2019-07-13 08:05:35 +02:00
def get_text(dictionary, *params):
text = dictionary[default_language]
if language in dictionary.keys():
text = dictionary[language]
2019-07-13 08:05:35 +02:00
return __insert_params__(text, params)
2019-07-13 08:05:35 +02:00
def __insert_params__(text, params):
index = 0
while '*%d' % index in text and index < len(params):
splitted = text.split('*%d' % index)
text = splitted[0] + str(params[index]) + splitted[1]
index += 1
while '*' in text:
splitted = text.split('*%d' % index)
if len(splitted) > 1:
text = splitted[0] + splitted[1].lstrip(' ')
else:
text = splitted[0].rsplit(' ')
index += 1
2019-07-13 08:05:35 +02:00
return text