Skip to content

Commit

Permalink
Add support for exporting english CSVs
Browse files Browse the repository at this point in the history
This resolves issue English translation #2
  • Loading branch information
AlexanderLill committed Mar 10, 2024
1 parent 2d2e568 commit 87c2305
Show file tree
Hide file tree
Showing 12 changed files with 1,482 additions and 27 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ Detailed examples of how the input looks like, and how the generated output look
## Command Line Arguments
```
cli.py -h
usage: cli.py [-h] [-cm CURRENCY_MAPPING] [-fc FIAT_CURRENCY] [-ir REFIDS_TO_IGNORE] [-o OUT_DIR] [-do DEPOT_OLD] [-dn DEPOT_NEW] [-a ACCOUNT] [-v]
[PP_RATES_FILE] [KRAKEN_CSV_FILE]
usage: cli.py [-h] [-cm CURRENCY_MAPPING] [-fc FIAT_CURRENCY] [-ir REFIDS_TO_IGNORE] [-o OUT_DIR] [-do DEPOT_OLD] [-dn DEPOT_NEW] [-a ACCOUNT]
[-v] [-l LANGUAGE] [PP_RATES_FILE] [KRAKEN_CSV_FILE]
Parse Kraken Crypto Transactions for Portfolio Performance Import.
Expand All @@ -64,6 +64,8 @@ options:
-a ACCOUNT, --account ACCOUNT
Name of account, def=ACCOUNT
-v, --verbose Activate verbose mode
-l LANGUAGE, --language LANGUAGE
Language for output (en/de, def=de)
```

Example:
Expand Down
6 changes: 4 additions & 2 deletions cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@
parser.add_argument('-o', '--out-dir', dest='out_dir', type=str, help='Directory to store PP transactions in (def=cwd)', default='.')
parser.add_argument('-do', '--depot-old', dest='depot_old', type=str, help="Name of current/old depot (def=DEPOT)", default="DEPOT")
parser.add_argument('-dn', '--depot-new', dest='depot_new', type=str, help="Name of new depot (target of transfers, def=DEPOT_NEW)", default="DEPOT_NEW")
parser.add_argument('-a', '--account', dest='account', type=str, help="Name of account, def=ACCOUNT", default="ACCOUNT")
parser.add_argument('-a', '--account', dest='account', type=str, help="Name of account (def=ACCOUNT)", default="ACCOUNT")
parser.add_argument('-v', '--verbose', dest='verbose', action='store_true', help='Activate verbose mode')
parser.add_argument('-l', '--language', dest='language', type=str, help='Language for output (en/de, def=de)', default='de')

args = parser.parse_args()

Expand All @@ -48,7 +49,8 @@
refids_to_ignore=args.refids_to_ignore,
depot_current=args.depot_old,
depot_new=args.depot_new,
account=args.account)
account=args.account,
language=args.language)

lp.store_depot_normal_transactions(f"{args.out_dir}/transactions_normal_depot.csv")
lp.store_depot_special_transactions(f"{args.out_dir}/transactions_special_depot.csv")
Expand Down
Empty file added src/i18n/__init__.py
Empty file.
8 changes: 8 additions & 0 deletions src/i18n/extra_de.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# these are taken from file portfolio/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages_de.properties
ColumnSecurity = Wertpapier
ColumnAmount = Betrag
ColumnNetValue = Gesamtpreis
ColumnSource = Quelle

Balance = Saldo
ColumnPerShare = pro Aktie
8 changes: 8 additions & 0 deletions src/i18n/extra_en.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# these are taken from file portfolio/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages.properties
ColumnSecurity = Security
ColumnAmount = Amount
ColumnNetValue = Net Transaction Value
ColumnSource = Source

Balance = Balance
ColumnPerShare = per share
75 changes: 75 additions & 0 deletions src/i18n/i18n.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
class I18n:

CSV_DEPOT_COLUMNS = [
'CSVColumn_Date',
'CSVColumn_Time',
'CSVColumn_Type',
'LabelSecurity',
'CSVColumn_Shares',
'CSVColumn_Quote',
'ColumnAmount',
'CSVColumn_Fees',
'CSVColumn_Taxes',
'ColumnNetValue',
'CSVColumn_AccountName',
'CSVColumn_AccountName2nd',
'CSVColumn_Note',
'ColumnSource'
]

CSV_ACCOUNT_COLUMNS = [
'CSVColumn_Date',
'CSVColumn_Time',
'CSVColumn_Type',
'ColumnAmount',
'Balance',
'ColumnSecurity',
'CSVColumn_Shares',
'ColumnPerShare',
'CSVColumn_AccountName2nd',
'CSVColumn_Note',
'ColumnSource'
]

def __init__(self, language):
self._constants = self.load_language(language)

self._constants['DEPOT_COLUMNS'] = self.translate_array(self.CSV_DEPOT_COLUMNS)
self._constants['ACCOUNT_COLUMNS'] = self.translate_array(self.CSV_ACCOUNT_COLUMNS)

def get(self, key):
return self._constants.get(key, key)

def load_language(self, language):
result = {}

prefix = "src/i18n"
files = [
f"{prefix}/labels_{language}.properties", # original file taken from original portfolio performance
f"{prefix}/messages_{language}.properties", # original file taken from original portfolio performance
f"{prefix}/extra_{language}.properties", # this file includes missing translations from other files
]
for f in files:
result.update(self.load_from_file(f))

return result

def load_from_file(self, filename):
result = {}
try:
with open(filename, encoding='utf-8') as f:
rows = f.readlines()
for row in rows:
if row.strip() and not row.startswith("#"):
row = row.encode('utf-8').decode('unicode-escape')
key, value = row.split(" = ")
result[key.strip()] = value.strip()
except Exception as e:
print(f"Error loading file {filename}: {e}")
return result

def translate_array(self, array):
result = []
for item in array:
result.append(self.get(item))
return result
25 changes: 25 additions & 0 deletions src/i18n/labels_de.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

account.BUY = Kauf
account.DEPOSIT = Einlage
account.DIVIDENDS = Dividende
account.FEES = Geb\u00FChren
account.FEES_REFUND = Geb\u00FChrenerstattung
account.INTEREST = Zinsen
account.INTEREST_CHARGE = Zinsbelastung
account.REMOVAL = Entnahme
account.SELL = Verkauf
account.TAXES = Steuern
account.TAX_REFUND = Steuerr\u00FCckerstattung
account.TRANSFER_IN = Umbuchung (Eingang)
account.TRANSFER_OUT = Umbuchung (Ausgang)

event.DIVIDEND_PAYMENT = Dividendenzahlung
event.NOTE = Notiz
event.STOCK_SPLIT = Aktiensplit

portfolio.BUY = Kauf
portfolio.DELIVERY_INBOUND = Einlieferung
portfolio.DELIVERY_OUTBOUND = Auslieferung
portfolio.SELL = Verkauf
portfolio.TRANSFER_IN = Umbuchung (Eingang)
portfolio.TRANSFER_OUT = Umbuchung (Ausgang)
25 changes: 25 additions & 0 deletions src/i18n/labels_en.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

account.BUY = Buy
account.DEPOSIT = Deposit
account.DIVIDENDS = Dividend
account.FEES = Fees
account.FEES_REFUND = Fees Refund
account.INTEREST = Interest
account.INTEREST_CHARGE = Interest Charge
account.REMOVAL = Removal
account.SELL = Sell
account.TAXES = Taxes
account.TAX_REFUND = Tax Refund
account.TRANSFER_IN = Transfer (Inbound)
account.TRANSFER_OUT = Transfer (Outbound)

event.DIVIDEND_PAYMENT = Dividend Payment
event.NOTE = Note
event.STOCK_SPLIT = Stock Split

portfolio.BUY = Buy
portfolio.DELIVERY_INBOUND = Delivery (Inbound)
portfolio.DELIVERY_OUTBOUND = Delivery (Outbound)
portfolio.SELL = Sell
portfolio.TRANSFER_IN = Transfer (Inbound)
portfolio.TRANSFER_OUT = Transfer (Outbound)
Loading

0 comments on commit 87c2305

Please sign in to comment.