From: changeling Date: Thu, 13 Dec 2018 20:12:01 +0000 (-0600) Subject: Replaced ordinal() function and calls with num2word module and calls. X-Git-Url: https://git.nutra.tk/v2?a=commitdiff_plain;h=93f27246306d35e92bf0dd1ccf28471d0c9f523d;p=gamesguru%2Fgetmyancestors.git Replaced ordinal() function and calls with num2word module and calls. Replaced ordinal() function and calls with num2word module and calls in fstogedcom.py and getmyancestors.py. Removed ordinal suffixes from translation.py. --- diff --git a/fstogedcom.py b/fstogedcom.py index 1b859ed..d5685a2 100644 --- a/fstogedcom.py +++ b/fstogedcom.py @@ -18,6 +18,12 @@ from getmyancestors import Session, Tree, Indi, Fam from mergemyancestors import Gedcom from translation import translations +try: + from num2words import num2words +except ImportError: + sys.stderr.write('You need to install the num2words module first\n') + sys.stderr.write('(run this in your terminal: "python3 -m pip install num2words" or "python3 -m pip install --user num2words")\n') + exit(2) tmp_dir = os.path.join(tempfile.gettempdir(), 'fstogedcom') global cache @@ -31,18 +37,6 @@ def _(string): return string -def ordinal(string): - if string[-1] == '1' and string[-2:] != '11': - suffix = _('st ') - elif string[-1] == '2' and string[-2:] != '12': - suffix = _('nd ') - elif string[-1] == '3' and string[-2:] != '13': - suffix = _('rd ') - else: - suffix = _('th ') - return string + suffix - - # Entry widget with right-clic menu to copy/cut/paste class EntryWithMenu(Entry): def __init__(self, master, **kw): @@ -438,7 +432,7 @@ class Download(Frame): if not todo: break done |= todo - self.info(_('Download ') + ordinal(str(i + 1)) + _('generation of ancestors...')) + self.info(_('Download ') + num2words(i + 1, to='ordinal_num', lang=lang) + _(' generation of ancestors...')) todo = self.tree.add_parents(todo) - done todo = set(self.tree.indi.keys()) @@ -447,7 +441,7 @@ class Download(Frame): if not todo: break done |= todo - self.info(_('Download ') + ordinal(str(i + 1)) + _('generation of descendants...')) + self.info(_('Download ') + num2words(i + 1, to='ordinal_num', lang=lang) + _(' generation of descendants...')) todo = self.tree.add_children(todo) - done if self.options.spouses.get(): diff --git a/getmyancestors.py b/getmyancestors.py index b7b5263..3a37a8f 100755 --- a/getmyancestors.py +++ b/getmyancestors.py @@ -33,6 +33,13 @@ import re # local import from translation import translations +try: + from num2words import num2words +except ImportError: + sys.stderr.write('You need to install the num2words module first\n') + sys.stderr.write('(run this in your terminal: "python3 -m pip install num2words" or "python3 -m pip install --user num2words")\n') + exit(2) + try: import requests except ImportError: @@ -104,18 +111,6 @@ def cont(string): return ('\n%s CONT ' % level).join(res) -def ordinal(string): - if string[-1] == '1' and string[-2:] != '11': - suffix = _('st ') - elif string[-1] == '2' and string[-2:] != '12': - suffix = _('nd ') - elif string[-1] == '3' and string[-2:] != '13': - suffix = _('rd ') - else: - suffix = _('th ') - return string + suffix - - # FamilySearch session class class Session: def __init__(self, username, password, verbose=False, logfile=sys.stderr, timeout=60): @@ -957,7 +952,7 @@ if __name__ == '__main__': if not todo: break done |= todo - print(_('Download ') + ordinal(str(i + 1)) + _('generation of ancestors...')) + print(_('Download ') + num2words(i + 1, to='ordinal_num', lang=fs.lang) + _(' generation of ancestors...')) todo = tree.add_parents(todo) - done # download descendants @@ -967,7 +962,7 @@ if __name__ == '__main__': if not todo: break done |= todo - print(_('Download ') + ordinal(str(i + 1)) + _('generation of descendants...')) + print(_('Download ') + num2words(i + 1, to='ordinal_num', lang=fs.lang) + _(' generation of descendants...')) todo = tree.add_children(todo) - done # download spouses diff --git a/translation.py b/translation.py index ba43089..9b4434c 100644 --- a/translation.py +++ b/translation.py @@ -101,23 +101,11 @@ translations = { 'Download starting individuals...': { 'fr': 'Téléchargement des personnes de départ...', }, - 'st ': { - 'fr': 'e ', + ' generation of ancestors...': { + 'fr': ' génération d\'ancêtres...', }, - 'nd ': { - 'fr': 'e ', - }, - 'rd ': { - 'fr': 'e ', - }, - 'th ': { - 'fr': 'e ', - }, - 'generation of ancestors...': { - 'fr': 'génération d\'ancêtres...', - }, - 'generation of descendants...': { - 'fr': 'génération de descendants...', + ' generation of descendants...': { + 'fr': ' génération de descendants...', }, 'Download spouses and marriage information...': { 'fr': 'Téléchargement des conjoints et des informations de mariage...',