mirror of https://github.com/django/django.git
Refs #30372 -- Stopped watching built-in Django translation files by auto-reloader.
This commit is contained in:
parent
8f10ceaa90
commit
c00bc27945
|
@ -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')
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue