]> git.ipfire.org Git - ipfire.org.git/commitdiff
web: Add a function to nicely format numbers
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 29 Dec 2025 16:46:50 +0000 (16:46 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 29 Dec 2025 16:46:50 +0000 (16:46 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
configure.ac
src/web/__init__.py

index d5505a3710960d1141e3ab6387294bd570a15406..aa75daaccc20f2680d38dec69abb4183932ff772 100644 (file)
@@ -30,6 +30,7 @@ AC_PROG_SED
 AM_PATH_PYTHON([3.11])
 
 AX_PYTHON_MODULE([PIL], [fatal])
+AX_PYTHON_MODULE([babel], [fatal])
 AX_PYTHON_MODULE([feedparser], [fatal])
 AX_PYTHON_MODULE([html2text], [fatal])
 AX_PYTHON_MODULE([iso3166], [fatal])
index 3e7ee30be2e5802ac2700da9b7d7ad7ed6de3b3a..4a653c6a2b1c58d93e300b0fd1d72645293b8e98 100644 (file)
@@ -1,5 +1,6 @@
 #/usr/bin/python
 
+import babel.numbers
 import logging
 import os.path
 import phonenumbers
@@ -56,6 +57,7 @@ class Application(tornado.web.Application):
                                "format_country_name"          : self.format_country_name,
                                "format_language_name"         : self.format_language_name,
                                "format_month_name"            : self.format_month_name,
+                               "format_number"                : self.format_number,
                                "format_phone_number"          : self.format_phone_number,
                                "format_phone_number_to_e164"  : self.format_phone_number_to_e164,
                                "format_phone_number_location" : self.format_phone_number_location,
@@ -445,6 +447,9 @@ class Application(tornado.web.Application):
 
                return month
 
+       def format_number(self, handler, *args, **kwargs):
+               return babel.numbers.format_number(*args, locale=handler.locale.code, **kwargs)
+
        def format_phone_number(self, handler, number):
                if not isinstance(number, phonenumbers.PhoneNumber):
                        try: