diff options
author | Lars-Dominik Braun <lars@6xq.net> | 2020-05-10 10:48:38 +0200 |
---|---|---|
committer | Lars-Dominik Braun <lars@6xq.net> | 2020-05-10 10:49:23 +0200 |
commit | 244197b5f8b1f4d73d4ab9ac838334860b55662c (patch) | |
tree | ce2d8cd63289f3457f227adea6fbcb0896e8dc26 /lulua/report.py | |
parent | 58a062d4f93b2ba362a94522d1a9b8e7c7f13469 (diff) | |
download | lulua-244197b5f8b1f4d73d4ab9ac838334860b55662c.tar.gz lulua-244197b5f8b1f4d73d4ab9ac838334860b55662c.tar.bz2 lulua-244197b5f8b1f4d73d4ab9ac838334860b55662c.zip |
report: Add translated source table, asymmetry definition
Also fix the layout break point.
Diffstat (limited to 'lulua/report.py')
-rw-r--r-- | lulua/report.py | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/lulua/report.py b/lulua/report.py index 9a08068..06bb724 100644 --- a/lulua/report.py +++ b/lulua/report.py @@ -28,10 +28,11 @@ from bokeh.resources import CDN as bokehres from .layout import LEFT, RIGHT, Direction, FingerType -def approx (i): +def approx (i, lang='en'): """ Get approximate human-readable string for large number """ - units = ['', 'thousand', 'million', 'billion'] + units = {'en': ['', 'thousand', 'million', 'billion'], + 'ar': ['', 'ألف', 'مليون', 'مليار']}[lang] base = Decimal (1000) i = Decimal (i) while round (i, 1) >= base and len (units) > 1: @@ -43,6 +44,16 @@ def numspace (s): """ Replace ordinary spaces with unicode FIGURE SPACE """ return s.replace (' ', '\u2007') +def arabnum (s): + """ + Convert number to arabic-indic ordinals. + + Granted, we could use setlocale and do proper formatting, but who has an + arabic locale installed…? + """ + m = {'0': '٠', '1': '١', '2': '٢', '3': '٣', '4': '٤', '5': '٥', '6': '٦', '7': '٧', '8': '٨', '9': '٩', ',': '٬', '.': '٫'} + return ''.join (map (lambda x: m.get (x, x), s)) + def render (): parser = argparse.ArgumentParser(description='Create lulua report.') parser.add_argument('-c', '--corpus', nargs='+', metavar='FILE', help='Corpus metadata files') @@ -55,6 +66,7 @@ def render (): ) env.filters['approx'] = approx env.filters['numspace'] = numspace + env.filters['arabnum'] = arabnum corpus = [] for x in args.corpus: |