taler-merchant-demos

Python-based Frontends for the Demonstration Web site
Log | Files | Refs | Submodules | README | LICENSE

commit 1576f3ea76329f4897411698016b09843e7d323a
parent 58a059b94afee29767303b399b48629985a48942
Author: Florian Dold <florian@dold.me>
Date:   Thu, 22 Apr 2021 14:03:09 +0200

locale selection

Diffstat:
Mtalermerchantdemos/blog/blog.py | 14++------------
Mtalermerchantdemos/donations/donations.py | 16+---------------
Mtalermerchantdemos/httpcommon/__init__.py | 1+
Mtalermerchantdemos/landing/landing.py | 3+++
Mtalermerchantdemos/survey/survey.py | 2++
5 files changed, 9 insertions(+), 27 deletions(-)

diff --git 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 @@ -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 @@ -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 @@ -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 @@ -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)))