From e98db55a16493a142600137befe5b2fa3576e811 Mon Sep 17 00:00:00 2001 From: Konstantin Kostov Date: Sat, 23 Nov 2024 14:26:14 +0100 Subject: [PATCH] feat: enable translations --- iamkonstantin_web/settings/base.py | 14 +++++++++++++- iamkonstantin_web/urls.py | 8 ++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/iamkonstantin_web/settings/base.py b/iamkonstantin_web/settings/base.py index 44ac0f7..4a71085 100644 --- a/iamkonstantin_web/settings/base.py +++ b/iamkonstantin_web/settings/base.py @@ -43,6 +43,7 @@ INSTALLED_APPS = [ "wagtail.images", "wagtail.search", "wagtail.admin", + "wagtail.locales", "wagtail", "modelcluster", "taggit", @@ -68,6 +69,7 @@ MIDDLEWARE = [ "django.middleware.security.SecurityMiddleware", "wagtail.contrib.redirects.middleware.RedirectMiddleware", "blog.middleware.BlogRedirectMiddleware", + "django.middleware.locale.LocaleMiddleware", "django_browser_reload.middleware.BrowserReloadMiddleware" ] @@ -128,7 +130,7 @@ AUTH_PASSWORD_VALIDATORS = [ # Internationalization # https://docs.djangoproject.com/en/5.0/topics/i18n/ -LANGUAGE_CODE = "en-us" +LANGUAGE_CODE = "en" TIME_ZONE = "UTC" @@ -136,6 +138,16 @@ USE_I18N = True USE_TZ = True +WAGTAIL_I18N_ENABLED = True + +USE_L10N = True # allows dates to be shown in the user's locale + +WAGTAIL_CONTENT_LANGUAGES = LANGUAGES = [ + ('en', "English"), + ('fr', "French"), + ('es', "Spanish"), + ('nl', "Dutch"), +] # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/5.0/howto/static-files/ diff --git a/iamkonstantin_web/urls.py b/iamkonstantin_web/urls.py index d53a50e..2f409b7 100644 --- a/iamkonstantin_web/urls.py +++ b/iamkonstantin_web/urls.py @@ -1,4 +1,5 @@ from django.conf import settings +from django.conf.urls.i18n import i18n_patterns from django.urls import include, path from django.contrib import admin from django.views.generic.base import TemplateView @@ -25,6 +26,13 @@ urlpatterns = [ path('newsletter/thanks', newsletter_views.thanks, name='thanks') ] +# Translatable URLs +# These will be available under a language code prefix. For example /en/search/ +urlpatterns += i18n_patterns( + path("", include(wagtail_urls)), + prefix_default_language=False, +) + if settings.DEBUG: from django.conf.urls.static import static from django.contrib.staticfiles.urls import staticfiles_urlpatterns