Skip to content

Commit c4ec1cd

Browse files
Added LOCALE_PATHS setting (#2213)
1 parent bf1ca4b commit c4ec1cd

File tree

5 files changed

+50
-1
lines changed

5 files changed

+50
-1
lines changed

.github/workflows/tests.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ jobs:
3333
uses: actions/setup-python@v5
3434
with:
3535
python-version: ${{ env.PYTHON_VERSION }}
36+
- name: Install gettext
37+
run: sudo apt-get update && sudo apt-get install -y gettext
3638
- name: Install dependencies
3739
run: |
3840
python -m pip install --upgrade pip setuptools

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@ APP_LIST ?= accounts aggregator blog contact dashboard djangoproject docs founda
44
SCSS = djangoproject/scss
55
STATIC = djangoproject/static
66

7-
ci: test
7+
ci: compilemessages test
88
@python -m coverage report
99

10+
compilemessages:
11+
python -m manage compilemessages
12+
1013
collectstatics: compile-scss
1114
python -m manage collectstatic --noinput
1215

djangoproject/settings/common.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,13 @@
217217

218218
TIME_ZONE = "America/Chicago"
219219

220+
# Internationalization settings
221+
220222
USE_I18N = True
221223

224+
# Django discovers locale directories in the installed apps on its own,
225+
# but the main project locale directory needs to be listed explicitly.
226+
LOCALE_PATHS = (BASE_DIR / "locale",)
222227

223228
USE_TZ = False
224229

djangoproject/tests.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,49 @@
44
from django.core.management import call_command
55
from django.test import TestCase
66
from django.urls import NoReverseMatch, get_resolver
7+
from django.utils.translation import activate, gettext as _
78
from django_hosts.resolvers import reverse
89

910
from docs.models import DocumentRelease, Release
1011

1112

13+
class LocaleSmokeTests(TestCase):
14+
"""
15+
Smoke test a translated string from each of the 3 locale directories
16+
(one defined in settings.LOCALE_PATHS, plus the dashboard and docs apps).
17+
"""
18+
19+
def test_dashboard_locale(self):
20+
"""dashboard/locale/ should contain translations for 'Development dashboard'"""
21+
activate("fr")
22+
translated = _("Development dashboard")
23+
self.assertEqual(
24+
translated,
25+
"Tableau de bord de développement",
26+
msg="dashboard/locale/ translation not loaded or incorrect",
27+
)
28+
29+
def test_docs_locale(self):
30+
"""docs/locale/ should contain translations for 'Using Django'"""
31+
activate("fr")
32+
translated = _("Using Django")
33+
self.assertEqual(
34+
translated,
35+
"Utilisation de Django",
36+
msg="docs/locale/ translation not loaded or incorrect",
37+
)
38+
39+
def test_project_locale(self):
40+
"""locale/ should contain translations for 'Fundraising'"""
41+
activate("fr")
42+
translated = _("Fundraising")
43+
self.assertEqual(
44+
translated,
45+
"Levée de fonds",
46+
msg="project-level locale/ translation not loaded or incorrect",
47+
)
48+
49+
1250
class TemplateViewTests(TestCase):
1351
"""
1452
Tests for views that are instances of TemplateView.

update-translations.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
set -ex
88

9+
# Any non-app directories added here must also be added to settings.LOCALE_PATHS
910
LOCALE_DIRS="dashboard/locale/ docs/locale/ locale/"
1011

1112
tx pull -a -f --minimum-perc=70

0 commit comments

Comments
 (0)