Replaced ordinal() function and calls with num2word module and calls.
authorchangeling <cklarson@gmail.com>
Thu, 13 Dec 2018 20:12:01 +0000 (14:12 -0600)
committerchangeling <cklarson@gmail.com>
Thu, 13 Dec 2018 20:12:01 +0000 (14:12 -0600)
Replaced ordinal() function and calls with num2word module and calls in fstogedcom.py and getmyancestors.py.

Removed ordinal suffixes from translation.py.

fstogedcom.py
getmyancestors.py
translation.py

index 1b859ede321b843eded9864fb5c8e26ade4a42ef..d5685a20ad7b7f836afbba3ac2b07ecfe56a089f 100644 (file)
@@ -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():
index b7b52636502c22aa1fd3754b9f40940ff51db050..3a37a8f85b109ac5b7b1d3732a45d20d847d9156 100755 (executable)
@@ -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
index ba43089701b9b23949d968fd99965fd7dd193069..9b4434c7f25fd94b99501f93fa5df6d13427b479 100644 (file)
@@ -101,23 +101,11 @@ translations = {
     'Download starting individuals...': {
         'fr': 'Téléchargement des personnes de départ...',
     },
-    'st ': {
-        'fr': '',
+    ' 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...',