diff --git a/kadenios/settings/common.py b/kadenios/settings/common.py index 6e0051e..acad986 100644 --- a/kadenios/settings/common.py +++ b/kadenios/settings/common.py @@ -6,6 +6,7 @@ import os import sys from django.urls import reverse_lazy +from django.utils.translation import gettext_lazy as _ # ############################################################################# # Secrets @@ -59,6 +60,7 @@ INSTALLED_APPS = [ MIDDLEWARE = [ "django.middleware.security.SecurityMiddleware", "django.contrib.sessions.middleware.SessionMiddleware", + "django.middleware.locale.LocaleMiddleware", "django.middleware.common.CommonMiddleware", "django.middleware.csrf.CsrfViewMiddleware", "django.contrib.auth.middleware.AuthenticationMiddleware", @@ -132,6 +134,13 @@ USE_I18N = True USE_L10N = True USE_TZ = True +LANGUAGES = [ + ("fr", _("Français")), + ("en", _("Anglais")), +] + +LOCALE_PATHS = [os.path.join(BASE_DIR, "shared", "locale")] + # ############################################################################# # Paramètres des fichiers statiques # ############################################################################# diff --git a/kadenios/urls.py b/kadenios/urls.py index 23c2a95..4c81a39 100644 --- a/kadenios/urls.py +++ b/kadenios/urls.py @@ -10,6 +10,7 @@ urlpatterns = [ path("elections/", include("elections.urls")), path("auth/", include("shared.auth.urls")), path("authens/", include("authens.urls")), + path("i18n/", include("django.conf.urls.i18n")), ] if "debug_toolbar" in settings.INSTALLED_APPS: diff --git a/shared/static/images/en.svg b/shared/static/images/en.svg new file mode 100644 index 0000000..132dbed --- /dev/null +++ b/shared/static/images/en.svg @@ -0,0 +1,7 @@ + diff --git a/shared/static/images/fr.svg b/shared/static/images/fr.svg new file mode 100644 index 0000000..712c8a5 --- /dev/null +++ b/shared/static/images/fr.svg @@ -0,0 +1,7 @@ + diff --git a/shared/templates/base.html b/shared/templates/base.html index e4dd889..af7b276 100644 --- a/shared/templates/base.html +++ b/shared/templates/base.html @@ -82,6 +82,16 @@ } }); + // Language selection + var $langs = document.querySelectorAll('.dropdown-item.lang-selector') || []; + + $langs.forEach($lang => { + $lang.addEventListener('click', () => { + document.getElementById('lang-input').value = $lang.dataset.lang; + document.getElementById('lang-form').submit(); + }); + }); + }); @@ -105,8 +115,47 @@ - {% block auth %}