Merge pull request #1799 from Bouke/tickets/9523

Fixed #9523 -- Restart runserver after translation MO files change
This commit is contained in:
Aymeric Augustin 2013-11-02 06:57:50 -07:00
commit 8b3d9d96ed
7 changed files with 82 additions and 5 deletions

View File

@ -369,6 +369,7 @@ answer newbie questions, and generally made Django that much better:
knox <christobzr@gmail.com>
David Krauth
Kevin Kubasik <kevin@kubasik.net>
Krzysztof Kulewski <kulewski@gmail.com>
kurtiss@meetro.com
Vladimir Kuzma <vladimirkuzma.ch@gmail.com>
Denis Kuzmichyov <kuzmichyov@gmail.com>

View File

@ -28,13 +28,13 @@
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import datetime
import os
import signal
import sys
import time
import traceback
from django.conf import settings
from django.core.signals import request_finished
try:
from django.utils.six.moves import _thread as thread
@ -86,13 +86,28 @@ _win = (sys.platform == "win32")
_error_files = []
def gen_filenames():
"""
Yields a generator over filenames referenced in sys.modules.
Yields a generator over filenames referenced in sys.modules and translation
files.
"""
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))
for filename in filenames + _error_files:
if not filename:
continue

View File

@ -791,8 +791,12 @@ Django.)
The development server automatically reloads Python code for each request, as
needed. You don't need to restart the server for code changes to take effect.
However, some actions like adding files or compiling translation files don't
trigger a restart, so you'll have to restart the server in these cases.
However, some actions like adding files don't trigger a restart, so you'll
have to restart the server in these cases.
.. versionchanged:: 1.7
Compiling translation files now also restarts the development server.
If you are using Linux and install `pyinotify`_, kernel signals will be used to
autoreload the server (rather than polling file modification timestamps each

View File

@ -346,6 +346,9 @@ Management Commands
* The :djadmin:`runserver` command now uses ``inotify`` Linux kernel signals
for autoreloading if ``pyinotify`` is installed.
* The :djadmin:`runserver` command is now restarted when a translation file is
changed.
Models
^^^^^^

Binary file not shown.

View File

@ -0,0 +1,17 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2007-09-15 19:15+0200\n"
"PO-Revision-Date: 2010-05-12 12:41-0300\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"

View File

@ -0,0 +1,37 @@
import os
from django import conf
from django.test import TestCase, override_settings
from django.utils.autoreload import gen_filenames
LOCALE_PATH = os.path.join(os.path.dirname(__file__), 'locale')
class TestFilenameGenerator(TestCase):
def test_django_locales(self):
"""
Test that gen_filenames() also yields the built-in django locale files.
"""
filenames = list(gen_filenames())
locales = []
basedir = os.path.join(os.path.dirname(conf.__file__), 'locale')
for dirpath, dirnames, locale_filenames in os.walk(basedir):
for filename in locale_filenames:
if filename.endswith('.mo'):
locales.append(os.path.join(dirpath, filename))
self.assertTrue(len(locales) > 10) # assume a few available locales
for filename in locales:
self.assertIn(filename, filenames)
@override_settings(
LOCALE_PATHS=(LOCALE_PATH,)
)
def test_app_locales(self):
"""
Test that gen_filenames also yields from LOCALE_PATHS.
"""
filenames = list(gen_filenames())
self.assertIn(os.path.join(LOCALE_PATH, 'nl', 'LC_MESSAGES', 'django.mo'),
filenames)