From 01123c36fd7517cba220c0fd029bbf1be41724be Mon Sep 17 00:00:00 2001 From: Julian Rother <julianr@fsmpi.rwth-aachen.de> Date: Sun, 25 Jul 2021 12:11:40 +0200 Subject: [PATCH] Disabled German translations by default and fixed language selection in this case --- uffd/__init__.py | 5 ++--- uffd/default_config.cfg | 9 +++++---- uffd/templates/base.html | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/uffd/__init__.py b/uffd/__init__.py index d815ecad..8bd5e263 100644 --- a/uffd/__init__.py +++ b/uffd/__init__.py @@ -129,10 +129,9 @@ def create_app(test_config=None): # pylint: disable=too-many-locals @babel.localeselector def get_locale(): #pylint: disable=unused-variable language_cookie = request.cookies.get('language') - if language_cookie is not None: + if language_cookie is not None and language_cookie in app.config['LANGUAGES']: return language_cookie - languages = list(map(lambda x: x.get('value'), app.config['LANGUAGES'])) - return request.accept_languages.best_match(languages) + return request.accept_languages.best_match(list(app.config['LANGUAGES'])) app.add_template_global(get_locale) diff --git a/uffd/default_config.cfg b/uffd/default_config.cfg index f0ab701d..00e39f7b 100644 --- a/uffd/default_config.cfg +++ b/uffd/default_config.cfg @@ -53,10 +53,11 @@ SESSION_COOKIE_SECURE=True SESSION_COOKIE_HTTPONLY=True SESSION_COOKIE_SAMESITE='Strict' -LANGUAGES=[ - { "value": "de", "display": "DE" }, - { "value": "en", "display": "EN" } -] +LANGUAGES={ + # Language identifier (see Accept-Language HTTP header) -> Display Name + "en": "EN", + #"de": "DE", # Too incomplete right now to enable per default +} ACL_ADMIN_GROUP="uffd_admin" ACL_SELFSERVICE_GROUP="uffd_access" diff --git a/uffd/templates/base.html b/uffd/templates/base.html index 4e8e4a51..f07351bc 100644 --- a/uffd/templates/base.html +++ b/uffd/templates/base.html @@ -76,8 +76,8 @@ <form class="language-switch py-2 pr-1" method="POST" style="margin-left: -5px;" action="{{ url_for('setlang') }}"> <input type="hidden" name="ref" value="{{ request.url }}"> <select name="lang" class="bg-dark" style="border: 0px; color: rgba(255, 255, 255, 0.5);" onchange="$('.language-switch').submit()"> - {% for language in config['LANGUAGES'] %} - <option value="{{ language['value'] }}" {{ 'selected' if language['value'] == get_locale() }}>{{ language['display'] }}</option> + {% for identifier, name in config['LANGUAGES'].items() %} + <option value="{{ identifier }}" {{ 'selected' if identifier == get_locale() }}>{{ name }}</option> {% endfor %} </select> <noscript> -- GitLab