Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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 jezdez authored
20 django/utils/translation/__init__.py
View
@@ -1,6 +1,7 @@
"""
Internationalization support.
"""
+import warnings
from os import path
from django.utils.encoding import force_unicode
@@ -41,17 +42,20 @@ def __getattr__(self, real_name):
from django.conf import settings
if settings.USE_I18N:
from django.utils.translation import trans_real as trans
-
+ # Make sure the project's locale dir isn't in LOCALE_PATHS
if settings.SETTINGS_MODULE is not None:
- import warnings
parts = settings.SETTINGS_MODULE.split('.')
project = import_module(parts[0])
- if path.isdir(path.join(path.dirname(project.__file__), 'locale')):
- warnings.warn(
- "Translations in the project directory aren't supported anymore. Use the LOCALE_PATHS setting instead.",
- PendingDeprecationWarning
- )
-
+ project_locale_path = path.normpath(
+ path.join(path.dirname(project.__file__), 'locale'))
+ normalized_locale_paths = [path.normpath(locale_path)
+ for locale_path in settings.LOCALE_PATHS]
+ if (path.isdir(project_locale_path) and
+ not project_locale_path in normalized_locale_paths):
+ warnings.warn("Translations in the project directory "
+ "aren't supported anymore. Use the "
+ "LOCALE_PATHS setting instead.",
+ PendingDeprecationWarning)
else:
from django.utils.translation import trans_null as trans
setattr(self, real_name, getattr(trans, real_name))
32 tests/regressiontests/i18n/test_warnings.py
View
@@ -0,0 +1,32 @@
+from os.path import join, normpath, abspath, dirname
+import warnings
+
+import django
+from django.conf import settings
+from django.test.utils import get_warnings_state, restore_warnings_state
+from django.utils.unittest import TestCase
+
+
+class DeprecationWarningTests(TestCase):
+
+ def setUp(self):
+ self.warning_state = get_warnings_state()
+ self.old_settings_module = settings.SETTINGS_MODULE
+ settings.SETTINGS_MODULE = 'regressiontests'
+ self.old_locale_paths = settings.LOCALE_PATHS
+
+ def tearDown(self):
+ restore_warnings_state(self.warning_state)
+ settings.SETTINGS_MODULE = self.old_settings_module
+ settings.LOCALE_PATHS = self.old_locale_paths
+
+ def test_no_warn_if_project_and_locale_paths_overlap(self):
+ """Test that PendingDeprecationWarning isn't generated when a deprecated project level locale/ subdir is also included in LOCALE_PATHS."""
+ project_path = join(dirname(abspath(__file__)), '..')
+ settings.LOCALE_PATHS += (normpath(join(project_path, 'locale')),)
+ warnings.filterwarnings('error', "Translations in the project directory aren't supported anymore\. Use the LOCALE_PATHS setting instead\.", PendingDeprecationWarning)
+ reload(django.utils.translation)
+ try:
+ django.utils.translation.ugettext('Time')
+ except PendingDeprecationWarning:
+ 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
View
@@ -24,6 +24,7 @@
from commands.tests import *
+from test_warnings import DeprecationWarningTests
class TranslationTests(TestCase):
Please sign in to comment.
Something went wrong with that request. Please try again.