from localconfig import TRANSLATIONSFILE import csv class Translations(): def __init__(self): ''' Download the business unit CSV from the GK reporting server or pick it up from disk :param self: Description ''' # open csv file to read in all the stores to invoice self.data = [] with open(TRANSLATIONSFILE, newline="", encoding="utf-8") as f_in: reader = csv.DictReader(f_in) for row in reader: self.data.append([row['type'],row['country'],row['from'],row['to']]) def translate(self, fromvalue, type='', country='all'): # print(f"translating {fromvalue} {country}") translations = [] for kv in self.data: if fromvalue==kv[2] and ( type=='' or type==kv[0]) and (country=='all' or country==kv[1]): translations.append(kv[3]) if len(translations) == 1: return translations[0] else: if country != 'all': return self.translate(fromvalue, type) return f"pos: {fromvalue}"