From 244197b5f8b1f4d73d4ab9ac838334860b55662c Mon Sep 17 00:00:00 2001 From: Lars-Dominik Braun Date: Sun, 10 May 2020 10:48:38 +0200 Subject: report: Add translated source table, asymmetry definition Also fix the layout break point. --- lulua/report.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'lulua/report.py') 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: -- cgit v1.2.3