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 diff --git a/djangoproject/settings/common.py b/djangoproject/settings/common.py index f36e44411a..fff6e1dfee 100644 --- a/djangoproject/settings/common.py +++ b/djangoproject/settings/common.py @@ -217,8 +217,13 @@ TIME_ZONE = "America/Chicago" +# Internationalization settings + USE_I18N = True +# 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 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. diff --git a/update-translations.sh b/update-translations.sh index 6d0fda4322..30a888ef4d 100755 --- a/update-translations.sh +++ b/update-translations.sh @@ -6,6 +6,7 @@ set -ex +# 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