diff --git a/hot_osm/settings/base.py b/hot_osm/settings/base.py index b2d35f1..bb5edc1 100644 --- a/hot_osm/settings/base.py +++ b/hot_osm/settings/base.py @@ -51,6 +51,8 @@ "django.contrib.messages", "django.contrib.staticfiles", "compressor", + "wagtail_localize", + "wagtail_localize.locales", ] MIDDLEWARE = [ @@ -61,6 +63,7 @@ "django.contrib.messages.middleware.MessageMiddleware", "django.middleware.clickjacking.XFrameOptionsMiddleware", "django.middleware.security.SecurityMiddleware", + "django.middleware.locale.LocaleMiddleware", "wagtail.contrib.redirects.middleware.RedirectMiddleware", ] @@ -129,8 +132,16 @@ USE_I18N = True +WAGTAIL_I18N_ENABLED = True + USE_TZ = True +WAGTAIL_CONTENT_LANGUAGES = [ + ("en", "English"), + ("fr", "French"), + ("es", "Spanish"), +] + # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/4.2/howto/static-files/ diff --git a/hot_osm/urls.py b/hot_osm/urls.py index 40ec083..523c031 100644 --- a/hot_osm/urls.py +++ b/hot_osm/urls.py @@ -1,4 +1,5 @@ from django.conf import settings +from django.conf.urls.i18n import i18n_patterns from django.contrib import admin from django.urls import include, path from wagtail import urls as wagtail_urls @@ -11,7 +12,6 @@ path("django-admin/", admin.site.urls), path("admin/", include(wagtailadmin_urls)), path("documents/", include(wagtaildocs_urls)), - path("search/", search_views.search, name="search"), path("__reload__/", include("django_browser_reload.urls")), ] @@ -24,12 +24,15 @@ urlpatterns += staticfiles_urlpatterns() urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) -urlpatterns = urlpatterns + [ - # For anything not caught by a more specific rule above, hand over to - # Wagtail's page serving mechanism. This should be the last pattern in - # the list: - path("", include(wagtail_urls)), - # Alternatively, if you want Wagtail pages to be served from a subpath - # of your site, rather than the site root: - # path("pages/", include(wagtail_urls)), -] +urlpatterns.extend( + i18n_patterns( + # For anything not caught by a more specific rule above, hand over to + # Wagtail's page serving mechanism. This should be the last pattern in + # the list: + path("", include(wagtail_urls)), + path("search/", search_views.search, name="search"), + # Alternatively, if you want Wagtail pages to be served from a subpath + # of your site, rather than the site root: + # path("pages/", include(wagtail_urls)), + ) +) diff --git a/poetry.lock b/poetry.lock index 9050c34..0ae1392 100644 --- a/poetry.lock +++ b/poetry.lock @@ -833,6 +833,17 @@ files = [ dev = ["pre-commit", "tox"] testing = ["pytest", "pytest-benchmark"] +[[package]] +name = "polib" +version = "1.2.0" +description = "A library to manipulate gettext files (po and mo files)." +optional = false +python-versions = "*" +files = [ + {file = "polib-1.2.0-py2.py3-none-any.whl", hash = "sha256:1c77ee1b81feb31df9bca258cbc58db1bbb32d10214b173882452c73af06d62d"}, + {file = "polib-1.2.0.tar.gz", hash = "sha256:f3ef94aefed6e183e342a8a269ae1fc4742ba193186ad76f175938621dbfc26b"}, +] + [[package]] name = "pre-commit" version = "3.5.0" @@ -1308,6 +1319,28 @@ Willow = {version = ">=1.6.2,<1.7", extras = ["heif"]} docs = ["Sphinx (>=1.5.2)", "myst-parser (==0.18.1)", "pyenchant (>=3.1.1,<4)", "sphinx-autobuild (>=0.6.0)", "sphinx-copybutton (>=0.5,<1.0)", "sphinx-wagtail-theme (==6.1.1)", "sphinxcontrib-spelling (>=5.4.0,<6)"] testing = ["Jinja2 (>=3.0,<3.2)", "azure-mgmt-cdn (>=12.0,<13.0)", "azure-mgmt-frontdoor (>=1.0,<1.1)", "black (==22.3.0)", "boto3 (>=1.28,<2)", "coverage (>=3.7.0)", "curlylint (==0.13.1)", "django-pattern-library (>=0.7,<0.8)", "djhtml (==1.5.2)", "doc8 (==0.8.1)", "factory-boy (>=3.2)", "freezegun (>=0.3.8)", "polib (>=1.1,<2.0)", "python-dateutil (>=2.7)", "pytz (>=2014.7)", "ruff (==0.0.290)", "semgrep (==1.40.0)", "tblib (>=2.0,<3.0)"] +[[package]] +name = "wagtail-localize" +version = "1.7" +description = "Translation plugin for Wagtail CMS" +optional = false +python-versions = ">=3.8" +files = [ + {file = "wagtail_localize-1.7-py3-none-any.whl", hash = "sha256:4c4a5792abb1ce5b75c287801bc5abeb704390936569629bc8ea9b0f58235bad"}, + {file = "wagtail_localize-1.7.tar.gz", hash = "sha256:313d887fbc60d9a535e1778473e0aab1069eb1a51f23b12b5e02750a0c1f6eb5"}, +] + +[package.dependencies] +Django = ">=3.2,<5.0" +polib = ">=1.1,<2.0" +typing_extensions = ">=4.0" +Wagtail = ">=4.1" + +[package.extras] +documentation = ["mkdocs (==1.4.3)", "mkdocs-autorefs (>=0.4.0,<0.5)", "mkdocs-include-markdown-plugin (>=4.0.4,<5)", "mkdocs-material (>=9.1,<10)", "mkdocstrings[python] (==0.22.0)", "pygments (>=2.15,<2.16)"] +google = ["google-cloud-translate (>=3.0.0)"] +testing = ["dj-database-url (>=2.1.0,<3)", "django-rq (>=2.5,<3.0)", "freezegun (>=1.2,<2)", "google-cloud-translate (>=3.0.0)", "pre-commit (>=3.4,<4)"] + [[package]] name = "webencodings" version = "0.5.1" @@ -1362,4 +1395,4 @@ testing = ["Pillow (>=9.1.0,<11.0.0)", "Wand (>=0.6,<1.0)", "black (==22.3.0)", [metadata] lock-version = "2.0" python-versions = "^3.11" -content-hash = "4b9efddf98cc2719a9b336ef25dcf2e7e5aa3ff7ea7edfec15ec37bdb08b78a0" +content-hash = "c8b3deebd76179a19eccf87d92f5361131ee9dcd5e7439d213497bde660c97d3" diff --git a/pyproject.toml b/pyproject.toml index 82b0e31..8ba470c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -29,6 +29,7 @@ python-dotenv = "^1.0.0" docker = "^6.1.3" gunicorn = "^21.2.0" django-compressor = "^4.4" +wagtail-localize = "^1.7" [tool.poetry.dev-dependencies]