summaryrefslogtreecommitdiff
path: root/talermerchantdemos/httpcommon
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2021-04-22 13:57:43 +0200
committerFlorian Dold <florian@dold.me>2021-04-22 13:57:43 +0200
commit58a059b94afee29767303b399b48629985a48942 (patch)
treeb82d875c06fa1e81439bd251604f8014816136d9 /talermerchantdemos/httpcommon
parentc8730857293c694449110ec289210e7ec4f32aa4 (diff)
downloadtaler-merchant-demos-58a059b94afee29767303b399b48629985a48942.tar.gz
taler-merchant-demos-58a059b94afee29767303b399b48629985a48942.tar.bz2
taler-merchant-demos-58a059b94afee29767303b399b48629985a48942.zip
refactor base template, language selector
Diffstat (limited to 'talermerchantdemos/httpcommon')
-rw-r--r--talermerchantdemos/httpcommon/__init__.py56
1 files changed, 56 insertions, 0 deletions
diff --git a/talermerchantdemos/httpcommon/__init__.py b/talermerchantdemos/httpcommon/__init__.py
index 39cd696..785494b 100644
--- a/talermerchantdemos/httpcommon/__init__.py
+++ b/talermerchantdemos/httpcommon/__init__.py
@@ -5,6 +5,8 @@ from flask import request
from datetime import datetime
import time
from flask_babel import gettext
+import os
+import re
class BackendException(Exception):
@@ -129,3 +131,57 @@ class Deadline:
)
)
return now > self.value
+
+
+all_languages = {
+ "en": "English [en]",
+ "ar": "Arabic [ar]",
+ "zh_Hant": "Chinese [zh]",
+ "fr": "French [fr]",
+ "de": "German [de]",
+ "hi": "Hindi [hi]",
+ "it": "Italian [it]",
+ "ja": "Japanese [ja]",
+ "ko": "Korean [ko]",
+ "pt": "Portuguese [pt]",
+ "pt_BR": "Portuguese (Brazil) [pt_BR]",
+ "ru": "Russian [ru]",
+ "es": "Spanish [es]",
+ "sv": "Swedish [sv]",
+ "tr": "Turkish [tr]",
+}
+
+
+
+##
+# Make the environment available into templates.
+#
+# @return the environment-reading function
+def make_utility_processor(pagename):
+ def utility_processor():
+ def getactive():
+ return pagename
+
+ def getlang():
+ return get_locale()
+
+ def env(name, default=None):
+ return os.environ.get(name, default)
+
+ def prettydate(talerdate):
+ parsed_time = re.search(r"/Date\(([0-9]+)\)/", talerdate)
+ if not parsed_time:
+ return "malformed date given"
+ parsed_time = int(parsed_time.group(1))
+ timestamp = datetime.datetime.fromtimestamp(parsed_time)
+ # returns the YYYY-MM-DD date format.
+ return timestamp.strftime("%Y-%b-%d")
+
+ return dict(
+ env=env,
+ prettydate=prettydate,
+ getactive=getactive,
+ getlang=getlang,
+ all_languages=all_languages,
+ )
+ return utility_processor