diff --git a/uffd/__init__.py b/uffd/__init__.py index d815ecad9952517f0845a794c6180e7839a101f9..8bd5e263f7e86a2f21ef5a6a4427eaea9da2dffd 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 f0ab701d067066bd342ff27f18575a473db7b9dc..00e39f7b11143961a470112730c7c484d4a25f6d 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 4e8e4a5155a36f7c49dc671492895d92aab87853..f07351bcdd8ee348f3e2d2598368175edc77076f 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>