1
0
mirror of https://github.com/django/django.git synced 2025-10-25 14:46:09 +00:00

Fixed #9523 -- Restart runserver after compiling apps translations

Django also uses locales provided by apps, which also might change. Also when
i18n is disabled, there is no need for watching translation files.
This commit is contained in:
Bouke Haarsma
2013-11-05 14:30:31 +01:00
committed by Aymeric Augustin
parent 15592a04d7
commit 2397daab4a
2 changed files with 66 additions and 29 deletions

View File

@@ -37,6 +37,9 @@ import traceback
from django.conf import settings
from django.core.signals import request_finished
from django.utils._os import upath
from django.utils.importlib import import_module
from django.utils.translation.trans_real import all_locale_paths
from django.utils import six
try:
from django.utils.six.moves import _thread as thread
@@ -97,19 +100,24 @@ def gen_filenames():
filenames = [filename.__file__ for filename in sys.modules.values()
if hasattr(filename, '__file__')]
# Add the names of the .mo files that can be generated
# by compilemessages management command to the list of files watched.
basedirs = [os.path.join(os.path.dirname(os.path.dirname(__file__)),
'conf', 'locale'),
'locale']
basedirs.extend(settings.LOCALE_PATHS)
basedirs = [os.path.abspath(basedir) for basedir in basedirs
if os.path.isdir(basedir)]
for basedir in basedirs:
for dirpath, dirnames, locale_filenames in os.walk(basedir):
for filename in locale_filenames:
if filename.endswith('.mo'):
filenames.append(os.path.join(dirpath, filename))
if settings.USE_I18N:
# Add the names of the .mo files that can be generated
# by compilemessages management command to the list of files watched.
basedirs = [os.path.join(os.path.dirname(os.path.dirname(__file__)),
'conf', 'locale'),
'locale']
for appname in reversed(settings.INSTALLED_APPS):
app = import_module(appname)
basedirs.append(os.path.join(os.path.dirname(upath(app.__file__)),
'locale'))
basedirs.extend(settings.LOCALE_PATHS)
basedirs = [os.path.abspath(basedir) for basedir in basedirs
if os.path.isdir(basedir)]
for basedir in basedirs:
for dirpath, dirnames, locale_filenames in os.walk(basedir):
for filename in locale_filenames:
if filename.endswith('.mo'):
filenames.append(os.path.join(dirpath, filename))
for filename in filenames + _error_files:
if not filename: