diff options
author | Jannis M. Hoffmann <jannis@fehcom.de> | 2024-11-01 17:34:33 +0100 |
---|---|---|
committer | Jannis M. Hoffmann <jannis@fehcom.de> | 2024-11-01 17:34:33 +0100 |
commit | 38dc1cde0d8ff6c52c39ec71be14a98946f04bad (patch) | |
tree | a80a50a03897920ff3723f3fb527516b7b2f6838 | |
parent | 820d861066ab444a7fa14ca16b40352e7fdf43f1 (diff) |
localize file sizes
-rw-r--r-- | src/jwebmail/__init__.py | 13 | ||||
-rw-r--r-- | src/jwebmail/templates/_folders.html | 2 | ||||
-rw-r--r-- | src/jwebmail/templates/_main_table.html | 2 |
3 files changed, 15 insertions, 2 deletions
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 @@ <span class="column has-text-centered"> {% if total_size %} {% trans %}mailbox size: {% endtrans %} - {{ total_size|filesizeformat }} + {{ total_size|filesizeformat|num_localize }} {% endif %} </span> </div> 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 @@ </div> <div class="column is-2"> - {{ msg.byte_size|filesizeformat }} + {{ msg.byte_size|filesizeformat|num_localize }} </div> </div> </div> |