Skip to content

Commit

Permalink
Import message improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
thalman committed Feb 6, 2024
1 parent ee92af3 commit 69f69ef
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions src/neknihy.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,24 @@ def __init__(self, configfile, debug=False):
self.updateBookList()
self.syncButtonMonitor()

self.gettext_map = {
"pridano": [
"Do čtečky byla přidána %i kniha, ",
"Do čtečky byly přidány %i knihy, ",
"Do čtečky bylo přidáno %i knih, "
],
"odstraneno": [
"odstraněna byla %i kniha, ",
"odstraněny byly %i knihy, ",
"odstraněno bylo %i knih, "
],
"celkem": [
"ve čtečce je %i vypůjčená kniha.",
"ve čtečce jsou %i vypůjčené knihy.",
"ve čtečce je %i vypůjčených knih."
]
}

def _resourcesFolder(self):
for resources in [
os.path.join(os.path.abspath(os.path.dirname(__file__)), 'resources'),
Expand Down Expand Up @@ -74,6 +92,7 @@ def addTooltip(self, button, tip):
def createGUI(self):
resources = self._resourcesFolder()
self._window = tk.Tk()
self._window.option_add('*Dialog.msg.font', 'Helvetica 12')
self._window.title("Neknihy")
self._window.geometry("800x600")
self._window.minsize(600, 400)
Expand Down Expand Up @@ -343,17 +362,24 @@ def onReturnBooks(self):
self.app.returnBooks()
self.updateBookList()

def gettext(self, sentence, amount):
idx = 0
if amount > 1:
idx = 1
if amount >= 5 or amount == 0:
idx = 2
return self.gettext_map[sentence][idx] % (amount)

def syncReader(self):
try:
self._message = None
self._error = None
result = self.app.syncReader()
if result is not None:
self._message = (
"Přidáno/odstraněno/zůstává ve čtečce: %i/%i/%i" % (
len(result["added"]),
len(result["removed"]),
result["total"])
self.gettext("pridano", len(result["added"])) +
self.gettext("odstraneno", len(result["removed"])) +
self.gettext("celkem", result["total"])
)
except Exception as e:
self._error = str(e)
Expand Down

0 comments on commit 69f69ef

Please sign in to comment.