Skip to content
Snippets Groups Projects
Verified Commit d0443327 authored by Tom Teichler's avatar Tom Teichler :beers:
Browse files

Allow site local configuration of available languages. Closes #261.

parent d8cc3412
No related branches found
No related tags found
No related merge requests found
Pipeline #4272 failed
......@@ -22,6 +22,7 @@ notification = Section("notification")
footer = Section("footer")
account = Section("account")
auth = Section("auth", verbose_name=_("Authentication"))
internationalization = Section("internationalization", verbose_name=_("Internationalization"))
@site_preferences_registry.register
......@@ -196,3 +197,12 @@ class AuthenticationBackends(MultipleChoicePreference):
def get_choices(self):
return [(b, b) for b in settings.CUSTOM_AUTHENTICATION_BACKENDS]
@site_preferences_registry.register
class AvailableLanguages(MultipleChoicePreference):
section = internationalization
name = "languages"
default = None
verbose_name = _("Available languages")
field_attribute = {"initial": []}
choices = settings.LANGUAGES
{# -*- engine:django -*- #}
{% load i18n %}
{% load i18n data_helpers %}
<form action="{% url 'set_language' %}" method="post" class="language-form">
......@@ -8,7 +8,7 @@
<input name="next" type="hidden" value="{{ request.get_full_path }}">
{% get_current_language as LANGUAGE_CODE %}
{% get_available_languages as LANGUAGES %}
{% get_enabled_languages as LANGUAGES %}
{% get_language_info_list for LANGUAGES as languages %}
{# Select #}
......
......@@ -5,6 +5,8 @@ from django import template
from django.contrib.contenttypes.models import ContentType
from django.db.models import Model
from aleksis.core.util.core_helpers import get_site_preferences
register = template.Library()
......@@ -51,3 +53,10 @@ def parse_json(value: Optional[str] = None) -> Union[dict, None]:
if not value:
return None
return json.loads(value)
@register.simple_tag
def get_enabled_languages() -> Any:
"""Template tag to get all available languages configured in settings."""
return get_site_preferences()["internationalization__languages"]
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment