From 78a6992f90bf1cab410e47ebd0e2abf39a6d6b08 Mon Sep 17 00:00:00 2001 From: Mauro Scomparin Date: Tue, 10 Jul 2018 19:46:57 +0200 Subject: [PATCH] english string translation --- money/money.py | 55 +++++++++++++++++++++------------------ money/tests/test_money.py | 2 +- 2 files changed, 31 insertions(+), 26 deletions(-) diff --git a/money/money.py b/money/money.py index 0b947cb..b559663 100755 --- a/money/money.py +++ b/money/money.py @@ -9,16 +9,21 @@ LAST_MOVEMENT_NUMBER = 'latestMovementsNumber' CONFIG_FILE_NAME = 'money.conf' CONFIG_FILE_LOCATION = expanduser('~') + '/.config/' + CONFIG_FILE_NAME +TYPE_FIELD_NAME = 'tipo' +VALUE_FIELD_NAME = 'valore' +DATE_FIELD_NAME = 'data' +HOUR_FIELD_NAME = 'ora' +DESCRIPTION_FIELD_NAME = 'descrizione' def scrivi_movimento(path, m): with open(path, 'a') as f: - f.write(m['tipo'] + m['valore']) + f.write(m[TYPE_FIELD_NAME] + m[VALUE_FIELD_NAME]) f.write(';') - f.write(m['data']) + f.write(m[DATE_FIELD_NAME]) f.write(';') - f.write(m['ora']) + f.write(m[HOUR_FIELD_NAME]) f.write(';') - f.write(m['descrizione']) + f.write(m[DESCRIPTION_FIELD_NAME]) f.write('\n') return @@ -26,7 +31,7 @@ def scrivi_movimento(path, m): def leggi_tipo(): t = 'n' while not (t == '' or t == '+' or t == '-'): - t = input('tipo (+/-) [-]: ') + t = input('type (+/-) [-]: ') if t == '': t = '-' elif t == '+': @@ -37,26 +42,26 @@ def leggi_tipo(): def leggi_valore(): v = '' while v == '': - v = input('valore (#####.##) []: ') + v = input('value (#####.##) []: ') return v def leggi_data(): - d = input('data (DD/MM/YYYY) [oggi]: ') + d = input('data (DD/MM/YYYY) [today]: ') if d == '': d = strftime("%d/%m/%Y", localtime()) return d def leggi_ora(): - o = input('ora (HH:MM) [adesso]: ') + o = input('hour (HH:MM) [now]: ') if o == '': o = strftime('%H:%M', localtime()) return o def leggi_descrizione(): - d = input('descrizione () []: ') + d = input('description () []: ') return d @@ -67,11 +72,11 @@ def leggi_movimento(): ora = leggi_ora() descrizione = leggi_descrizione() m = { - 'tipo': tipo, - 'valore': valore, - 'data': data, - 'ora': ora, - 'descrizione': descrizione + TYPE_FIELD_NAME: tipo, + VALUE_FIELD_NAME: valore, + DATE_FIELD_NAME: data, + HOUR_FIELD_NAME: ora, + DESCRIPTION_FIELD_NAME: descrizione } return m @@ -88,10 +93,10 @@ def carica_file(f): for l in df: spl = l.split(';') d = { - 'valore': spl[0], - 'data': spl[1], - 'ora': spl[2], - 'descrizione': spl[3] + VALUE_FIELD_NAME: spl[0], + DATE_FIELD_NAME: spl[1], + HOUR_FIELD_NAME: spl[2], + DESCRIPTION_FIELD_NAME: spl[3] } dati.append(d) return dati @@ -165,8 +170,8 @@ def ordina(dati): return sorted( dati, key=lambda x: ( - data_default(x['data']), - ora_default(x['ora']) + data_default(x[DATE_FIELD_NAME]), + ora_default(x[HOUR_FIELD_NAME]) ), reverse=True ) @@ -176,7 +181,7 @@ def default_configuration(): return {DATA_FILE_NAME: 'movimenti.dat', LAST_MOVEMENT_NUMBER: 5} def last_movement_number_message(n): - return 'ultimi {} movimenti:'.format(n) + return 'latest {} movements:'.format(n) def riassunto(file_dati, conf): dati = carica_file(file_dati) @@ -185,15 +190,15 @@ def riassunto(file_dati, conf): spese_tot = Decimal('0') guadagni_tot = Decimal('0') for d in dati: - m = Decimal(d['valore']) + m = Decimal(d[VALUE_FIELD_NAME]) val_attuale = val_attuale + m if m > Decimal('0'): guadagni_tot = guadagni_tot + m else: spese_tot = spese_tot + m - print('valore attuale:', str(val_attuale)) - print('guadagni complessivi:', str(guadagni_tot)) - print('spese complessive:', str(spese_tot)) + print('actual value:', str(val_attuale)) + print('total incomes:', str(guadagni_tot)) + print('total expenses:', str(spese_tot)) print(last_movement_number_message(conf[LAST_MOVEMENT_NUMBER])) for i in range(conf[LAST_MOVEMENT_NUMBER]): if i < len(dati_ordinati): diff --git a/money/tests/test_money.py b/money/tests/test_money.py index ffb616a..1cad1f2 100644 --- a/money/tests/test_money.py +++ b/money/tests/test_money.py @@ -11,7 +11,7 @@ class MoneyTest(unittest.TestCase): self.assertTrue(True, msg='se fallisce son problemi') def test_riassunto_last_movement_number(self): - self.assertEqual(money.last_movement_number_message(10), "ultimi 10 movimenti:") + self.assertEqual(money.last_movement_number_message(10), "latest 10 movements:") def test_config_file_name(self): self.assertEqual(money.CONFIG_FILE_NAME, 'money.conf') -- 2.25.1