From b250a8c108f1c0cd2f459b4e7c0dedcfaca1c117 Mon Sep 17 00:00:00 2001 From: Tobias McNulty Date: Sat, 20 Sep 2025 08:17:42 -0400 Subject: [PATCH 1/6] Added `LOCALE_PATHS` setting --- djangoproject/settings/common.py | 8 ++++++++ update-translations.sh | 1 + 2 files changed, 9 insertions(+) diff --git a/djangoproject/settings/common.py b/djangoproject/settings/common.py index f36e44411a..c3a2570d3b 100644 --- a/djangoproject/settings/common.py +++ b/djangoproject/settings/common.py @@ -217,8 +217,16 @@ TIME_ZONE = "America/Chicago" +# Internationalization settings + USE_I18N = True +LOCALE_PATHS = [ + # List apps first so their translations take precedence. + # This list should match LOCALE_DIRS in update-translations.sh. + str(BASE_DIR.joinpath(path)) + for path in ("dashboard/locale/", "docs/locale/", "locale/") +] USE_TZ = False diff --git a/update-translations.sh b/update-translations.sh index 6d0fda4322..fad78750db 100755 --- a/update-translations.sh +++ b/update-translations.sh @@ -6,6 +6,7 @@ set -ex +# This list should match the LOCALE_PATHS in djangoproject/settings/common.py LOCALE_DIRS="dashboard/locale/ docs/locale/ locale/" tx pull -a -f --minimum-perc=70 From 593c874889ecf33d9df8436651a592f77c89afd7 Mon Sep 17 00:00:00 2001 From: Tobias McNulty Date: Sat, 20 Sep 2025 13:45:13 -0400 Subject: [PATCH 2/6] Added tests for translated strings --- djangoproject/tests.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/djangoproject/tests.py b/djangoproject/tests.py index a95f0b939f..759f0a3292 100644 --- a/djangoproject/tests.py +++ b/djangoproject/tests.py @@ -4,11 +4,49 @@ from django.core.management import call_command from django.test import TestCase from django.urls import NoReverseMatch, get_resolver +from django.utils.translation import activate, gettext as _ from django_hosts.resolvers import reverse from docs.models import DocumentRelease, Release +class LocaleSmokeTests(TestCase): + """ + Smoke test a translated string from each of the 3 locale directories + (one defined in settings.LOCALE_PATHS, plus the dashboard and docs apps). + """ + + def test_dashboard_locale(self): + """dashboard/locale/ should contain translations for 'Development dashboard'""" + activate("fr") + translated = _("Development dashboard") + self.assertEqual( + translated, + "Tableau de bord de développement", + msg="dashboard/locale/ translation not loaded or incorrect", + ) + + def test_docs_locale(self): + """docs/locale/ should contain translations for 'Using Django'""" + activate("fr") + translated = _("Using Django") + self.assertEqual( + translated, + "Utilisation de Django", + msg="docs/locale/ translation not loaded or incorrect", + ) + + def test_project_locale(self): + """locale/ should contain translations for 'Fundraising'""" + activate("fr") + translated = _("Fundraising") + self.assertEqual( + translated, + "Levée de fonds", + msg="project-level locale/ translation not loaded or incorrect", + ) + + class TemplateViewTests(TestCase): """ Tests for views that are instances of TemplateView. From baa75cf4a2198eabaea1da23a2d47baad98fd3ce Mon Sep 17 00:00:00 2001 From: Tobias McNulty Date: Sat, 20 Sep 2025 13:52:19 -0400 Subject: [PATCH 3/6] Simplified LOCALE_PATHS --- djangoproject/settings/common.py | 10 ++++------ update-translations.sh | 2 +- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/djangoproject/settings/common.py b/djangoproject/settings/common.py index c3a2570d3b..11d45c5077 100644 --- a/djangoproject/settings/common.py +++ b/djangoproject/settings/common.py @@ -221,12 +221,10 @@ USE_I18N = True -LOCALE_PATHS = [ - # List apps first so their translations take precedence. - # This list should match LOCALE_DIRS in update-translations.sh. - str(BASE_DIR.joinpath(path)) - for path in ("dashboard/locale/", "docs/locale/", "locale/") -] +# Django discovers locale directories in the dashboard and docs apps +# on its own, but the main project locale/ directory needs to be +# explicitly listed here. +LOCALE_PATHS = [str(BASE_DIR.joinpath("locale/"))] USE_TZ = False diff --git a/update-translations.sh b/update-translations.sh index fad78750db..30a888ef4d 100755 --- a/update-translations.sh +++ b/update-translations.sh @@ -6,7 +6,7 @@ set -ex -# This list should match the LOCALE_PATHS in djangoproject/settings/common.py +# Any non-app directories added here must also be added to settings.LOCALE_PATHS LOCALE_DIRS="dashboard/locale/ docs/locale/ locale/" tx pull -a -f --minimum-perc=70 From acb4ccf29e32e294df804eea0afc4ed7579db129 Mon Sep 17 00:00:00 2001 From: Tobias McNulty Date: Sat, 20 Sep 2025 13:55:24 -0400 Subject: [PATCH 4/6] Added compilemessages to ci --- .github/workflows/tests.yml | 2 ++ Makefile | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 0b7c22ecf5..0ceef41d84 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -33,6 +33,8 @@ jobs: uses: actions/setup-python@v5 with: python-version: ${{ env.PYTHON_VERSION }} + - name: Install gettext + run: sudo apt-get update && sudo apt-get install -y gettext - name: Install dependencies run: | python -m pip install --upgrade pip setuptools diff --git a/Makefile b/Makefile index 2bf7ed7063..78f59e8997 100644 --- a/Makefile +++ b/Makefile @@ -4,9 +4,12 @@ APP_LIST ?= accounts aggregator blog contact dashboard djangoproject docs founda SCSS = djangoproject/scss STATIC = djangoproject/static -ci: test +ci: compilemessages test @python -m coverage report +compilemessages: + python -m manage compilemessages + collectstatics: compile-scss python -m manage collectstatic --noinput From 9c9d75434b84b03330c2b16a243a772069fb14cc Mon Sep 17 00:00:00 2001 From: Tobias McNulty Date: Wed, 24 Sep 2025 12:02:21 -0400 Subject: [PATCH 5/6] formatting/comment cleanup --- djangoproject/settings/common.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/djangoproject/settings/common.py b/djangoproject/settings/common.py index 11d45c5077..d7ca8c349b 100644 --- a/djangoproject/settings/common.py +++ b/djangoproject/settings/common.py @@ -221,10 +221,11 @@ USE_I18N = True -# Django discovers locale directories in the dashboard and docs apps -# on its own, but the main project locale/ directory needs to be -# explicitly listed here. -LOCALE_PATHS = [str(BASE_DIR.joinpath("locale/"))] +# Django discovers locale directories in the installed apps on its own, +# but the main project locale directory needs to be listed explicitly. +LOCALE_PATHS = ( + BASE_DIR / "locale", +) USE_TZ = False From 7f5db2c9f0dbf23ac84885f2d5b17f7ca4ae412a Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 24 Sep 2025 16:02:54 +0000 Subject: [PATCH 6/6] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- djangoproject/settings/common.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/djangoproject/settings/common.py b/djangoproject/settings/common.py index d7ca8c349b..fff6e1dfee 100644 --- a/djangoproject/settings/common.py +++ b/djangoproject/settings/common.py @@ -223,9 +223,7 @@ # Django discovers locale directories in the installed apps on its own, # but the main project locale directory needs to be listed explicitly. -LOCALE_PATHS = ( - BASE_DIR / "locale", -) +LOCALE_PATHS = (BASE_DIR / "locale",) USE_TZ = False