You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

reloader.py 968B

12345678910111213141516171819202122232425262728
  1. import threading
  2. from pathlib import Path
  3. from django.apps import apps
  4. def watch_for_translation_changes(sender, **kwargs):
  5. """Register file watchers for .mo files in potential locale paths."""
  6. from django.conf import settings
  7. if settings.USE_I18N:
  8. directories = [Path('locale')]
  9. directories.extend(Path(config.path) / 'locale' for config in apps.get_app_configs())
  10. directories.extend(Path(p) for p in settings.LOCALE_PATHS)
  11. for path in directories:
  12. sender.watch_dir(path, '**/*.mo')
  13. def translation_file_changed(sender, file_path, **kwargs):
  14. """Clear the internal translations cache if a .mo file is modified."""
  15. if file_path.suffix == '.mo':
  16. import gettext
  17. from django.utils.translation import trans_real
  18. gettext._translations = {}
  19. trans_real._translations = {}
  20. trans_real._default = None
  21. trans_real._active = threading.local()
  22. return True