summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2021-04-22 14:03:09 +0200
committerFlorian Dold <florian@dold.me>2021-04-22 14:03:09 +0200
commit1576f3ea76329f4897411698016b09843e7d323a (patch)
tree9b5f2a57f1be6d30314fcc669608e367084678bd
parent58a059b94afee29767303b399b48629985a48942 (diff)
downloadtaler-merchant-demos-1576f3ea76329f4897411698016b09843e7d323a.tar.gz
taler-merchant-demos-1576f3ea76329f4897411698016b09843e7d323a.tar.bz2
taler-merchant-demos-1576f3ea76329f4897411698016b09843e7d323a.zip
locale selection
-rw-r--r--talermerchantdemos/blog/blog.py14
-rw-r--r--talermerchantdemos/donations/donations.py16
-rw-r--r--talermerchantdemos/httpcommon/__init__.py1
-rw-r--r--talermerchantdemos/landing/landing.py3
-rw-r--r--talermerchantdemos/survey/survey.py2
5 files changed, 9 insertions, 27 deletions
diff --git a/talermerchantdemos/blog/blog.py b/talermerchantdemos/blog/blog.py
index 2981f05..cb3d392 100644
--- a/talermerchantdemos/blog/blog.py
+++ b/talermerchantdemos/blog/blog.py
@@ -41,6 +41,7 @@ from talermerchantdemos.httpcommon import (
Deadline,
BackendException,
make_utility_processor,
+ get_locale,
)
@@ -97,6 +98,7 @@ BABEL_TRANSLATION_DIRECTORIES = "../translations"
app.config.from_object(__name__)
babel = Babel(app)
+babel.localeselector(get_locale)
LOGGER.info("Using translations from:" + ":".join(list(babel.translation_directories)))
translations = [str(translation) for translation in babel.list_translations()]
@@ -151,18 +153,6 @@ def favicon():
)
-@babel.localeselector
-def get_locale():
- parts = request.path.split("/", 2)
- if 2 >= len(parts):
- # Totally unexpected path format, do not localize
- return "en"
- lang = parts[1]
- if lang in translations:
- return lang
- return "en"
-
-
##
# Serve the main index page for a particular language.
#
diff --git a/talermerchantdemos/donations/donations.py b/talermerchantdemos/donations/donations.py
index 903952c..fa2b077 100644
--- a/talermerchantdemos/donations/donations.py
+++ b/talermerchantdemos/donations/donations.py
@@ -64,6 +64,7 @@ BABEL_TRANSLATION_DIRECTORIES = "../translations"
app.config.from_object(__name__)
babel = Babel(app)
+babel.localeselector(get_locale)
LOGGER.info("Using translations from:" + ":".join(list(babel.translation_directories)))
@@ -74,21 +75,6 @@ LOGGER.info(
"Operating with the following translations available: " + " ".join(translations)
)
-app.add_template_global(self_localized)
-
-
-@babel.localeselector
-def get_locale():
- parts = request.path.split("/", 2)
- if 2 >= len(parts):
- # Totally unexpected path format, do not localize
- return "en"
- lang = parts[1]
- if lang in translations:
- return lang
- return "en"
-
-
# Add context processor that will make additional variables
# and functions available in the template.
app.context_processor(make_utility_processor("donations"))
diff --git a/talermerchantdemos/httpcommon/__init__.py b/talermerchantdemos/httpcommon/__init__.py
index 785494b..2d1a294 100644
--- a/talermerchantdemos/httpcommon/__init__.py
+++ b/talermerchantdemos/httpcommon/__init__.py
@@ -88,6 +88,7 @@ def backend_get(backend_url, endpoint, params, auth_token=None):
return response_json
+babel.localeselector
def get_locale():
parts = request.path.split("/", 2)
if 2 >= len(parts):
diff --git a/talermerchantdemos/landing/landing.py b/talermerchantdemos/landing/landing.py
index 5b6376e..e158d3d 100644
--- a/talermerchantdemos/landing/landing.py
+++ b/talermerchantdemos/landing/landing.py
@@ -33,6 +33,7 @@ from ..httpcommon import (
backend_get,
backend_post,
self_localized,
+ get_locale,
make_utility_processor,
)
import sys
@@ -63,7 +64,9 @@ except ConfigurationError as ce:
BABEL_TRANSLATION_DIRECTORIES = "../translations"
app.config.from_object(__name__)
+
babel = Babel(app)
+babel.localeselector(get_locale)
LOGGER.info("Using translations from:" + ":".join(list(babel.translation_directories)))
translations = [str(translation) for translation in babel.list_translations()]
diff --git a/talermerchantdemos/survey/survey.py b/talermerchantdemos/survey/survey.py
index 466c14d..d583114 100644
--- a/talermerchantdemos/survey/survey.py
+++ b/talermerchantdemos/survey/survey.py
@@ -66,6 +66,8 @@ BABEL_TRANSLATION_DIRECTORIES = "../translations"
app.config.from_object(__name__)
babel = Babel(app)
+babel.localeselector(get_locale)
+
INSTANCED_URL = urljoin(BACKEND_URL, f"instances/survey/")
LOGGER.info("Using translations from:" + ":".join(list(babel.translation_directories)))