Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #15286 -- Don't show deprecation warning if project locale dir …

…is included in LOCALE_PATHS. Thanks to Claude and Ramiro.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@15508 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 179fefcf7c1e9c6f0a4db5b31a4444bee24e73fa 1 parent e1e3f24
Jannis Leidel authored February 12, 2011
20  django/utils/translation/__init__.py
... ...
@@ -1,6 +1,7 @@
1 1
 """
2 2
 Internationalization support.
3 3
 """
  4
+import warnings
4 5
 from os import path
5 6
 
6 7
 from django.utils.encoding import force_unicode
@@ -41,17 +42,20 @@ def __getattr__(self, real_name):
41 42
         from django.conf import settings
42 43
         if settings.USE_I18N:
43 44
             from django.utils.translation import trans_real as trans
44  
-
  45
+            # Make sure the project's locale dir isn't in LOCALE_PATHS
45 46
             if settings.SETTINGS_MODULE is not None:
46  
-                import warnings
47 47
                 parts = settings.SETTINGS_MODULE.split('.')
48 48
                 project = import_module(parts[0])
49  
-                if path.isdir(path.join(path.dirname(project.__file__), 'locale')):
50  
-                    warnings.warn(
51  
-                        "Translations in the project directory aren't supported anymore. Use the LOCALE_PATHS setting instead.",
52  
-                        PendingDeprecationWarning
53  
-                    )
54  
-
  49
+                project_locale_path = path.normpath(
  50
+                    path.join(path.dirname(project.__file__), 'locale'))
  51
+                normalized_locale_paths = [path.normpath(locale_path)
  52
+                    for locale_path in settings.LOCALE_PATHS]
  53
+                if (path.isdir(project_locale_path) and
  54
+                        not project_locale_path in normalized_locale_paths):
  55
+                    warnings.warn("Translations in the project directory "
  56
+                                  "aren't supported anymore. Use the "
  57
+                                  "LOCALE_PATHS setting instead.",
  58
+                                  PendingDeprecationWarning)
55 59
         else:
56 60
             from django.utils.translation import trans_null as trans
57 61
         setattr(self, real_name, getattr(trans, real_name))
32  tests/regressiontests/i18n/test_warnings.py
... ...
@@ -0,0 +1,32 @@
  1
+from os.path import join, normpath, abspath, dirname
  2
+import warnings
  3
+
  4
+import django
  5
+from django.conf import settings
  6
+from django.test.utils import get_warnings_state, restore_warnings_state
  7
+from django.utils.unittest import TestCase
  8
+
  9
+
  10
+class DeprecationWarningTests(TestCase):
  11
+
  12
+    def setUp(self):
  13
+        self.warning_state = get_warnings_state()
  14
+        self.old_settings_module = settings.SETTINGS_MODULE
  15
+        settings.SETTINGS_MODULE = 'regressiontests'
  16
+        self.old_locale_paths = settings.LOCALE_PATHS
  17
+
  18
+    def tearDown(self):
  19
+        restore_warnings_state(self.warning_state)
  20
+        settings.SETTINGS_MODULE = self.old_settings_module
  21
+        settings.LOCALE_PATHS = self.old_locale_paths
  22
+
  23
+    def test_no_warn_if_project_and_locale_paths_overlap(self):
  24
+        """Test that PendingDeprecationWarning isn't generated when a deprecated project level locale/ subdir is also included in LOCALE_PATHS."""
  25
+        project_path = join(dirname(abspath(__file__)), '..')
  26
+        settings.LOCALE_PATHS += (normpath(join(project_path, 'locale')),)
  27
+        warnings.filterwarnings('error', "Translations in the project directory aren't supported anymore\. Use the LOCALE_PATHS setting instead\.", PendingDeprecationWarning)
  28
+        reload(django.utils.translation)
  29
+        try:
  30
+            django.utils.translation.ugettext('Time')
  31
+        except PendingDeprecationWarning:
  32
+            self.fail("PendingDeprecationWarning shouldn't be raised when settings/project locale and a LOCALE_PATHS member point to the same file system location.")
1  tests/regressiontests/i18n/tests.py
@@ -24,6 +24,7 @@
24 24
 
25 25
 from commands.tests import *
26 26
 
  27
+from test_warnings import DeprecationWarningTests
27 28
 
28 29
 class TranslationTests(TestCase):
29 30
 

0 notes on commit 179fefc

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