Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #9523 -- Restart runserver after translation MO files change

Thanks to Krzysztof Kulewski for the initial patch.
  • Loading branch information...
commit c3936c0d79d79aced25ceba8beff0c91a6b5c2ed 1 parent 090315f
Bouke Haarsma authored November 02, 2013
1  AUTHORS
@@ -369,6 +369,7 @@ answer newbie questions, and generally made Django that much better:
369 369
     knox <christobzr@gmail.com>
370 370
     David Krauth
371 371
     Kevin Kubasik <kevin@kubasik.net>
  372
+    Krzysztof Kulewski <kulewski@gmail.com>
372 373
     kurtiss@meetro.com
373 374
     Vladimir Kuzma <vladimirkuzma.ch@gmail.com>
374 375
     Denis Kuzmichyov <kuzmichyov@gmail.com>
21  django/utils/autoreload.py
@@ -28,13 +28,13 @@
28 28
 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 29
 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 30
 
31  
-import datetime
32 31
 import os
33 32
 import signal
34 33
 import sys
35 34
 import time
36 35
 import traceback
37 36
 
  37
+from django.conf import settings
38 38
 from django.core.signals import request_finished
39 39
 try:
40 40
     from django.utils.six.moves import _thread as thread
@@ -86,13 +86,28 @@
86 86
 
87 87
 _error_files = []
88 88
 
89  
-
90 89
 def gen_filenames():
91 90
     """
92  
-    Yields a generator over filenames referenced in sys.modules.
  91
+    Yields a generator over filenames referenced in sys.modules and translation
  92
+    files.
93 93
     """
94 94
     filenames = [filename.__file__ for filename in sys.modules.values()
95 95
                 if hasattr(filename, '__file__')]
  96
+
  97
+    # Add the names of the .mo files that can be generated
  98
+    # by compilemessages management command to the list of files watched.
  99
+    basedirs = [os.path.join(os.path.dirname(os.path.dirname(__file__)),
  100
+                             'conf', 'locale'),
  101
+                'locale']
  102
+    basedirs.extend(settings.LOCALE_PATHS)
  103
+    basedirs = [os.path.abspath(basedir) for basedir in basedirs
  104
+                if os.path.isdir(basedir)]
  105
+    for basedir in basedirs:
  106
+        for dirpath, dirnames, locale_filenames in os.walk(basedir):
  107
+            for filename in locale_filenames:
  108
+                if filename.endswith('.mo'):
  109
+                    filenames.append(os.path.join(dirpath, filename))
  110
+
96 111
     for filename in filenames + _error_files:
97 112
         if not filename:
98 113
             continue
8  docs/ref/django-admin.txt
@@ -791,8 +791,12 @@ Django.)
791 791
 
792 792
 The development server automatically reloads Python code for each request, as
793 793
 needed. You don't need to restart the server for code changes to take effect.
794  
-However, some actions like adding files or compiling translation files don't
795  
-trigger a restart, so you'll have to restart the server in these cases.
  794
+However, some actions like adding files don't trigger a restart, so you'll 
  795
+have to restart the server in these cases.
  796
+
  797
+.. versionchanged:: 1.7
  798
+
  799
+    Compiling translation files now also restarts the development server.
796 800
 
797 801
 If you are using Linux and install `pyinotify`_, kernel signals will be used to
798 802
 autoreload the server (rather than polling file modification timestamps each
3  docs/releases/1.7.txt
@@ -346,6 +346,9 @@ Management Commands
346 346
 * The :djadmin:`runserver` command now uses ``inotify`` Linux kernel signals
347 347
   for autoreloading if ``pyinotify`` is installed.
348 348
 
  349
+* The :djadmin:`runserver` command is now restarted when a translation file is
  350
+  changed.
  351
+
349 352
 Models
350 353
 ^^^^^^
351 354
 
BIN  tests/utils_tests/locale/nl/LC_MESSAGES/django.mo
Binary file not shown
17  tests/utils_tests/locale/nl/LC_MESSAGES/django.po
... ...
@@ -0,0 +1,17 @@
  1
+# SOME DESCRIPTIVE TITLE.
  2
+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
  3
+# This file is distributed under the same license as the PACKAGE package.
  4
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
  5
+#
  6
+#, fuzzy
  7
+msgid ""
  8
+msgstr ""
  9
+"Project-Id-Version: PACKAGE VERSION\n"
  10
+"Report-Msgid-Bugs-To: \n"
  11
+"POT-Creation-Date: 2007-09-15 19:15+0200\n"
  12
+"PO-Revision-Date: 2010-05-12 12:41-0300\n"
  13
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
  14
+"Language-Team: LANGUAGE <LL@li.org>\n"
  15
+"MIME-Version: 1.0\n"
  16
+"Content-Type: text/plain; charset=UTF-8\n"
  17
+"Content-Transfer-Encoding: 8bit\n"
37  tests/utils_tests/test_autoreload.py
... ...
@@ -0,0 +1,37 @@
  1
+import os
  2
+
  3
+from django import conf
  4
+from django.test import TestCase, override_settings
  5
+from django.utils.autoreload import gen_filenames
  6
+
  7
+LOCALE_PATH = os.path.join(os.path.dirname(__file__), 'locale')
  8
+
  9
+
  10
+class TestFilenameGenerator(TestCase):
  11
+    def test_django_locales(self):
  12
+        """
  13
+        Test that gen_filenames() also yields the built-in django locale files.
  14
+        """
  15
+        filenames = list(gen_filenames())
  16
+        locales = []
  17
+
  18
+        basedir = os.path.join(os.path.dirname(conf.__file__), 'locale')
  19
+        for dirpath, dirnames, locale_filenames in os.walk(basedir):
  20
+            for filename in locale_filenames:
  21
+                if filename.endswith('.mo'):
  22
+                    locales.append(os.path.join(dirpath, filename))
  23
+
  24
+        self.assertTrue(len(locales) > 10)  # assume a few available locales
  25
+        for filename in locales:
  26
+            self.assertIn(filename, filenames)
  27
+
  28
+    @override_settings(
  29
+        LOCALE_PATHS=(LOCALE_PATH,)
  30
+    )
  31
+    def test_app_locales(self):
  32
+        """
  33
+        Test that gen_filenames also yields from LOCALE_PATHS.
  34
+        """
  35
+        filenames = list(gen_filenames())
  36
+        self.assertIn(os.path.join(LOCALE_PATH, 'nl', 'LC_MESSAGES', 'django.mo'),
  37
+                      filenames)

0 notes on commit c3936c0

Please sign in to comment.
Something went wrong with that request. Please try again.