Skip to content

Commit

Permalink
Add support for all languages supported by Portfolio Performance
Browse files Browse the repository at this point in the history
This commit adds portfolio performance as a submodule, allowing to access all i18n files available in portfolio performance.
  • Loading branch information
AlexanderLill committed Apr 6, 2024
1 parent 3da87ca commit 1f51013
Show file tree
Hide file tree
Showing 15 changed files with 117 additions and 1,439 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "resources/portfolio"]
path = resources/portfolio
url = https://github.com/portfolio-performance/portfolio.git
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ Detailed examples of how the input looks like, and how the generated output look
## Comments
- Project is a Work-in-Progress (WIP)

## Supported Portfolio Performance Languages
The list of supported languages can be found by checking which `messages_$LANG.properties` files exist here: https://github.com/portfolio-performance/portfolio/tree/master/name.abuchen.portfolio/src/name/abuchen/portfolio

## Step-by-step
1. Export all `ledger` data from kraken
1. On the kraken website, choose `History` in the top menu, then `Export`
Expand All @@ -25,12 +28,13 @@ Detailed examples of how the input looks like, and how the generated output look
2. Export all history crypto rates from Portfolio Performance (PP)
1. In PP, choose `File` - `Export` - `CSV...`
2. Scroll to the bottom and choose `Securities` - `All historic rates` and choose storage location
3. Run `cli.py` with the following parameters (see `cli.py` for help)
3. Run `git submodule init` to download the code of Portfolio Performance (necessary for translation files). The list of supported languages can be found by checking which `messages_$LANG.properties` files exist here: https://github.com/portfolio-performance/portfolio/tree/master/name.abuchen.portfolio/src/name/abuchen/portfolio
4. Run `cli.py` with the following parameters (see `cli.py` for help)
- `PP_RATES_FILE` historical rates file exported from PP (required)
- `KRAKEN_CSV_FILE` kraken ledger export (required)
- optional parameters (see section "Command Line Arguments")
- `-cm` can be used to specify mapping between PP Symbol and Kraken crypto currency abbreviation if they differ
4. Import the generated CSV files in Portfolio Performance
5. Import the generated CSV files in Portfolio Performance
- Import `transactions_account.csv` as account data (it includes deposits and withdrawals and costs for transfers)
- Import `transactions_normal_depot.csv` as transaction data (it includes buying and seeling cryptocurrencies)
- Import `transactions_special_depot.csv` as transaction data and **check the box to transform them to transfers instead of buys**
Expand Down
1 change: 1 addition & 0 deletions resources/portfolio
Submodule portfolio added at a47697
96 changes: 96 additions & 0 deletions src/i18n.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import os
from pathlib import Path

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._res_dir = self._determine_resource_dir()
print(f"Loading translations from: {self._res_dir}")

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 _determine_resource_dir(self):
proj_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
return proj_dir / Path("resources/portfolio")

def get(self, key):
if key in self._constants:
return self._constants[key]
else:
print(f"Error: Could not find key: {key}")
return self._constants.get(key, key)

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

if language == "en":
language = ""
else:
language = f"_{language}"

files = [
Path(f"name.abuchen.portfolio/src/name/abuchen/portfolio/model/labels{language}.properties"),
Path(f"name.abuchen.portfolio/src/name/abuchen/portfolio/messages{language}.properties"),
Path(f"name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/messages{language}.properties"),
]
for file in files:
full_file_name = Path(self._res_dir) / file
result.update(self._load_from_file(full_file_name))

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')
items = row.split(" = ")
key = items[0]
value = "".join(items[1:])
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
Empty file removed src/i18n/__init__.py
Empty file.
8 changes: 0 additions & 8 deletions src/i18n/extra_de.properties

This file was deleted.

8 changes: 0 additions & 8 deletions src/i18n/extra_en.properties

This file was deleted.

7 changes: 0 additions & 7 deletions src/i18n/i18n.md

This file was deleted.

79 changes: 0 additions & 79 deletions src/i18n/i18n.py

This file was deleted.

25 changes: 0 additions & 25 deletions src/i18n/labels_de.properties

This file was deleted.

25 changes: 0 additions & 25 deletions src/i18n/labels_en.properties

This file was deleted.

Loading

0 comments on commit 1f51013

Please sign in to comment.