From 38dc1cde0d8ff6c52c39ec71be14a98946f04bad Mon Sep 17 00:00:00 2001 From: "Jannis M. Hoffmann" Date: Fri, 1 Nov 2024 17:34:33 +0100 Subject: localize file sizes --- src/jwebmail/__init__.py | 13 +++++++++++++ src/jwebmail/templates/_folders.html | 2 +- src/jwebmail/templates/_main_table.html | 2 +- 3 files changed, 15 insertions(+), 2 deletions(-) (limited to 'src/jwebmail') diff --git a/src/jwebmail/__init__.py b/src/jwebmail/__init__.py index 01b364b..51df9d9 100644 --- a/src/jwebmail/__init__.py +++ b/src/jwebmail/__init__.py @@ -10,6 +10,7 @@ from flask_babel import Babel, get_locale from flask_login import LoginManager, login_required from flask_wtf.csrf import CSRFProtect from jinja2 import ChainableUndefined +from markupsafe import Markup from werkzeug.middleware.proxy_fix import ProxyFix from .css import compile_css_command @@ -83,6 +84,18 @@ def create_app(): route(app) + tr_dict = { + "en": str.maketrans({" ": " "}), + "de": str.maketrans({".": ",", " ": " "}), + } + + @app.template_filter("num_localize") + def num_localize(txt): + if str(get_locale()).startswith("de"): + return Markup(txt.translate(tr_dict["de"])) + else: + return Markup(txt.translate(tr_dict["en"])) + @app.context_processor def inject_version(): return { diff --git a/src/jwebmail/templates/_folders.html b/src/jwebmail/templates/_folders.html index 7b8f85d..7bee2a2 100644 --- a/src/jwebmail/templates/_folders.html +++ b/src/jwebmail/templates/_folders.html @@ -44,7 +44,7 @@ {% if total_size %} {% trans %}mailbox size: {% endtrans %} - {{ total_size|filesizeformat }} + {{ total_size|filesizeformat|num_localize }} {% endif %} diff --git a/src/jwebmail/templates/_main_table.html b/src/jwebmail/templates/_main_table.html index b6493fb..cc22da4 100644 --- a/src/jwebmail/templates/_main_table.html +++ b/src/jwebmail/templates/_main_table.html @@ -33,7 +33,7 @@
- {{ msg.byte_size|filesizeformat }} + {{ msg.byte_size|filesizeformat|num_localize }}
-- cgit v1.2.3