Coverage for /var/srv/projects/api.amasfac.comuna18.com/tmp/venv/lib/python3.9/site-packages/django/utils/translation/reloader.py: 19%
21 statements
« prev ^ index » next coverage.py v6.4.4, created at 2023-07-17 14:22 -0600
« prev ^ index » next coverage.py v6.4.4, created at 2023-07-17 14:22 -0600
1from pathlib import Path
3from asgiref.local import Local
5from django.apps import apps
6from django.utils.autoreload import is_django_module
9def watch_for_translation_changes(sender, **kwargs):
10 """Register file watchers for .mo files in potential locale paths."""
11 from django.conf import settings
13 if settings.USE_I18N:
14 directories = [Path("locale")]
15 directories.extend(
16 Path(config.path) / "locale"
17 for config in apps.get_app_configs()
18 if not is_django_module(config.module)
19 )
20 directories.extend(Path(p) for p in settings.LOCALE_PATHS)
21 for path in directories:
22 sender.watch_dir(path, "**/*.mo")
25def translation_file_changed(sender, file_path, **kwargs):
26 """Clear the internal translations cache if a .mo file is modified."""
27 if file_path.suffix == ".mo":
28 import gettext
30 from django.utils.translation import trans_real
32 gettext._translations = {}
33 trans_real._translations = {}
34 trans_real._default = None
35 trans_real._active = Local()
36 return True