frompathlibimportPathfromasgiref.localimportLocalfromdjango.appsimportappsfromdjango.utils.autoreloadimportis_django_moduledefwatch_for_translation_changes(sender,**kwargs):"""Register file watchers for .mo files in potential locale paths."""fromdjango.confimportsettingsifsettings.USE_I18N:directories=[Path("locale")]directories.extend(Path(config.path)/"locale"forconfiginapps.get_app_configs()ifnotis_django_module(config.module))directories.extend(Path(p)forpinsettings.LOCALE_PATHS)forpathindirectories:sender.watch_dir(path,"**/*.mo")deftranslation_file_changed(sender,file_path,**kwargs):"""Clear the internal translations cache if a .mo file is modified."""iffile_path.suffix==".mo":importgettextfromdjango.utils.translationimporttrans_realgettext._translations={}trans_real._translations={}trans_real._default=Nonetrans_real._active=Local()returnTrue