Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Show the currently selected language for the UI

Roland Geider4f6c9ae41557
diff --git a/wger/core/templates/tags/language_select.html b/wger/core/templates/tags/language_select.html
index 207d3b4e4..19d7b1932 100644
--- a/wger/core/templates/tags/language_select.html
+++ b/wger/core/templates/tags/language_select.html
@@ -3,7 +3,7 @@
<a class="dropdown-item" href="{{ i18n_path }}">
<img src="{% static path %}"
width="20"
- alt="{% translate language_name %}"
- title="{% translate language_name %}">
- {% translate language_name %} / <small>{{ language_name }}</small>
+ alt="{% translate name %}"
+ title="{% translate name %}">
+ {% translate name %} / <small>{{ name }}</small>
</a>
diff --git a/wger/core/templates/template.html b/wger/core/templates/template.html
index 0496443f3..bd59e86b0 100644
--- a/wger/core/templates/template.html
+++ b/wger/core/templates/template.html
@@ -193,11 +193,9 @@
<button id="btnGroupLanguages2" type="button"
class="btn btn-link text-muted small dropdown-toggle btn-sm"
data-toggle="dropdown">
- <img src="{% static language.static_path %}"
- width="20"
- alt="{% translate language.full_name %}"
- title="{% translate language.full_name %}">
- {{ language.full_name }} <span class="caret"></span>
+ <span class="{% fa_class 'globe' %}"></span>
+ {% translate i18n_language.name %}
+ <span class="caret"></span>
</button>
<div class="dropdown-menu dropdown-menu-right"
aria-labelledby="btnGroupLanguages">
diff --git a/wger/core/templatetags/wger_extras.py b/wger/core/templatetags/wger_extras.py
index c73fc22fc..f940213b3 100644
--- a/wger/core/templatetags/wger_extras.py
+++ b/wger/core/templatetags/wger_extras.py
@@ -34,6 +34,8 @@ from wger.utils.constants import (
PAGINATION_MAX_TOTAL_PAGES,
PAGINATION_PAGES_AROUND_CURRENT,
)
+from wger.utils.language import get_language_data
+
register = template.Library()
@@ -162,11 +164,7 @@ def language_select(context, language):
Renders a link to change the current language.
"""
- return {
- 'language_name': language[1],
- 'path': f'images/icons/flags/{language[0]}.svg',
- 'i18n_path': context['i18n_path'][language[0]]
- }
+ return {**get_language_data(language), 'i18n_path': context['i18n_path'][language[0]]}
@register.filter
diff --git a/wger/settings_global.py b/wger/settings_global.py
index 0d34c15a5..2eb3d4520 100644
--- a/wger/settings_global.py
+++ b/wger/settings_global.py
@@ -20,6 +20,7 @@ import os
import re
from datetime import timedelta
+
"""
This file contains the global settings that don't usually need to be changed.
For a full list of options, visit:
@@ -164,7 +165,8 @@ TEMPLATES = [
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
],
- 'debug': False
+ 'debug':
+ False
},
},
]
@@ -211,8 +213,8 @@ TIME_ZONE = 'UTC'
# Available languages. Needs to be kept in sync with sufficiently
# translated languages: https://hosted.weblate.org/projects/wger/web/
#
-# Translated languages for which exist a country specific locale in django
-# upstream need to be added as well (plus their country flag)
+# Translated languages for which a country specific locale exists in django
+# upstream need to be added here as well (plus their country flag)
# https://github.com/django/django/blob/main/django/conf/global_settings.py
AVAILABLE_LANGUAGES = (
('bg', 'Bulgarian'),
@@ -247,7 +249,7 @@ AVAILABLE_LANGUAGES = (
LANGUAGE_CODE = 'en'
# All translation files are in one place
-LOCALE_PATHS = (os.path.join(SITE_ROOT, 'locale'),)
+LOCALE_PATHS = (os.path.join(SITE_ROOT, 'locale'), )
# Primary keys are AutoFields
DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'
@@ -419,11 +421,15 @@ COMPRESS_ROOT = STATIC_ROOT
# Django Rest Framework
#
REST_FRAMEWORK = {
- 'DEFAULT_PERMISSION_CLASSES': ('wger.utils.permissions.WgerPermission',),
- 'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.LimitOffsetPagination',
- 'PAGE_SIZE': 20,
- 'PAGINATE_BY_PARAM': 'limit', # Allow client to override, using `?limit=xxx`.
- 'TEST_REQUEST_DEFAULT_FORMAT': 'json',
+ 'DEFAULT_PERMISSION_CLASSES': ('wger.utils.permissions.WgerPermission', ),
+ 'DEFAULT_PAGINATION_CLASS':
+ 'rest_framework.pagination.LimitOffsetPagination',
+ 'PAGE_SIZE':
+ 20,
+ 'PAGINATE_BY_PARAM':
+ 'limit', # Allow client to override, using `?limit=xxx`.
+ 'TEST_REQUEST_DEFAULT_FORMAT':
+ 'json',
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.SessionAuthentication',
'rest_framework.authentication.TokenAuthentication',
@@ -459,7 +465,7 @@ CORS_URLS_REGEX = r'^/api/.*$'
#
# Ignore these URLs if they cause 404
#
-IGNORABLE_404_URLS = (re.compile(r'^/favicon\.ico$'),)
+IGNORABLE_404_URLS = (re.compile(r'^/favicon\.ico$'), )
#
# Password rules
diff --git a/wger/utils/context_processor.py b/wger/utils/context_processor.py
index 00615a061..c388417a2 100644
--- a/wger/utils/context_processor.py
+++ b/wger/utils/context_processor.py
@@ -16,16 +16,16 @@
# Django
from django.conf import settings
from django.templatetags.static import static
-from django.utils.translation import get_language, to_locale
+from django.utils.translation import get_language
# wger
from wger.config.models import GymConfig
from wger.utils import constants
-from wger.utils.language import load_language
+from wger.utils.language import get_language_data
def processor(request):
- language = load_language()
+ languages_dict = dict(settings.AVAILABLE_LANGUAGES)
full_path = request.get_full_path()
i18n_path = {}
static_path = static('images/logos/logo-social.png')
@@ -38,10 +38,8 @@ def processor(request):
# Twitter handle for this instance
'twitter': settings.WGER_SETTINGS['TWITTER'],
- # User language
- 'language': language,
-
- # Available application languages
+ # Languages
+ 'i18n_language': get_language_data((get_language(), languages_dict[get_language()])),
'languages': settings.AVAILABLE_LANGUAGES,
# The current path
diff --git a/wger/utils/language.py b/wger/utils/language.py
index a0fa264b5..d2e435c6c 100644
--- a/wger/utils/language.py
+++ b/wger/utils/language.py
@@ -24,6 +24,7 @@ from wger.core.models import Language
from wger.utils.cache import cache_mapper
from wger.utils.constants import ENGLISH_SHORT_NAME
+
logger = logging.getLogger(__name__)
@@ -48,3 +49,7 @@ def load_language(language_code=None):
cache.set(cache_mapper.get_language_key(language.short_name), language)
return language
+
+
+def get_language_data(language):
+ return {'name': language[1], 'path': f'images/icons/flags/{language[0]}.svg'}