diff --git a/django/utils/translation/reloader.py b/django/utils/translation/reloader.py index 41d0623568..0e5a83699d 100644 --- a/django/utils/translation/reloader.py +++ b/django/utils/translation/reloader.py @@ -5,13 +5,22 @@ from asgiref.local import Local from django.apps import apps +def _is_django_module(module): + """Return True if the given module is nested under Django.""" + return module.__name__.startswith('django.') + + def watch_for_translation_changes(sender, **kwargs): """Register file watchers for .mo files in potential locale paths.""" from django.conf import settings if settings.USE_I18N: directories = [Path('locale')] - directories.extend(Path(config.path) / 'locale' for config in apps.get_app_configs()) + directories.extend( + Path(config.path) / 'locale' + for config in apps.get_app_configs() + if not _is_django_module(config.module) + ) directories.extend(Path(p) for p in settings.LOCALE_PATHS) for path in directories: sender.watch_dir(path, '**/*.mo') diff --git a/docs/releases/3.1.txt b/docs/releases/3.1.txt index 3edc8bf6e3..c4863a3ab4 100644 --- a/docs/releases/3.1.txt +++ b/docs/releases/3.1.txt @@ -683,6 +683,9 @@ Miscellaneous the previous behavior, pass ``ensure_ascii=True`` to JSON serializer, or ``allow_unicode=False`` to YAML serializer. +* The auto-reloader no longer monitors changes in built-in Django translation + files. + .. _deprecated-features-3.1: Features deprecated in 3.1 diff --git a/tests/i18n/tests.py b/tests/i18n/tests.py index cce32ea86c..8f07c14247 100644 --- a/tests/i18n/tests.py +++ b/tests/i18n/tests.py @@ -1865,6 +1865,12 @@ class WatchForTranslationChangesTests(SimpleTestCase): project_dir = Path(__file__).parent / 'sampleproject' / 'locale' mocked_sender.watch_dir.assert_any_call(project_dir, '**/*.mo') + def test_i18n_app_dirs_ignore_django_apps(self): + mocked_sender = mock.MagicMock() + with self.settings(INSTALLED_APPS=['django.contrib.admin']): + watch_for_translation_changes(mocked_sender) + mocked_sender.watch_dir.assert_called_once_with(Path('locale'), '**/*.mo') + def test_i18n_local_locale(self): mocked_sender = mock.MagicMock() watch_for_translation_changes(mocked_sender)