Ticket #18040: 18040.diff
File 18040.diff, 8.3 KB (added by , 13 years ago) |
---|
-
django/utils/translation/__init__.py
diff --git a/django/utils/translation/__init__.py b/django/utils/translation/__init__.py
a b 1 1 """ 2 2 Internationalization support. 3 3 """ 4 import warnings5 from os import path6 7 4 from django.utils.encoding import force_unicode 8 5 from django.utils.functional import lazy 9 from django.utils.importlib import import_module10 6 11 7 12 8 __all__ = [ … … 47 43 from django.conf import settings 48 44 if settings.USE_I18N: 49 45 from django.utils.translation import trans_real as trans 50 # Make sure the project's locale dir isn't in LOCALE_PATHS51 if settings.SETTINGS_MODULE is not None:52 parts = settings.SETTINGS_MODULE.split('.')53 project = import_module(parts[0])54 project_locale_path = path.normpath(55 path.join(path.dirname(project.__file__), 'locale'))56 normalized_locale_paths = [path.normpath(locale_path)57 for locale_path in settings.LOCALE_PATHS]58 if (path.isdir(project_locale_path) and59 not project_locale_path in normalized_locale_paths):60 warnings.warn("Translations in the project directory "61 "aren't supported anymore. Use the "62 "LOCALE_PATHS setting instead.",63 DeprecationWarning)64 46 else: 65 47 from django.utils.translation import trans_null as trans 66 48 setattr(self, real_name, getattr(trans, real_name)) -
django/utils/translation/trans_real.py
diff --git a/django/utils/translation/trans_real.py b/django/utils/translation/trans_real.py
a b 111 111 112 112 globalpath = os.path.join(os.path.dirname(sys.modules[settings.__module__].__file__), 'locale') 113 113 114 if settings.SETTINGS_MODULE is not None:115 parts = settings.SETTINGS_MODULE.split('.')116 project = import_module(parts[0])117 projectpath = os.path.join(os.path.dirname(project.__file__), 'locale')118 else:119 projectpath = None120 121 114 def _fetch(lang, fallback=None): 122 115 123 116 global _translations … … 163 156 if os.path.isdir(apppath): 164 157 res = _merge(apppath) 165 158 166 localepaths = [os.path.normpath(path) for path in settings.LOCALE_PATHS]167 if (projectpath and os.path.isdir(projectpath) and168 os.path.normpath(projectpath) not in localepaths):169 res = _merge(projectpath)170 171 159 for localepath in reversed(settings.LOCALE_PATHS): 172 160 if os.path.isdir(localepath): 173 161 res = _merge(localepath) -
deleted file tests/regressiontests/i18n/test_warnings.py
diff --git a/tests/regressiontests/i18n/test_warnings.py b/tests/regressiontests/i18n/test_warnings.py deleted file mode 100644
+ - 1 import warnings2 from os.path import join, normpath, abspath, dirname3 4 import django5 from django.conf import settings6 from django.test.utils import get_warnings_state, restore_warnings_state7 from django.utils.translation import _trans8 from django.utils.unittest import TestCase9 10 11 class DeprecationWarningTests(TestCase):12 13 def setUp(self):14 self.warning_state = get_warnings_state()15 self.old_settings_module = settings.SETTINGS_MODULE16 settings.SETTINGS_MODULE = 'regressiontests'17 self.old_locale_paths = settings.LOCALE_PATHS18 19 def tearDown(self):20 restore_warnings_state(self.warning_state)21 settings.SETTINGS_MODULE = self.old_settings_module22 settings.LOCALE_PATHS = self.old_locale_paths23 24 def test_warn_if_project_has_locale_subdir(self):25 """Test that DeprecationWarning is generated when a deprecated project level locale/ subdir is present."""26 project_path = join(dirname(abspath(__file__)), '..')27 warnings.filterwarnings('error',28 "Translations in the project directory aren't supported anymore\. Use the LOCALE_PATHS setting instead\.",29 DeprecationWarning)30 _trans.__dict__ = {}31 self.assertRaises(DeprecationWarning, django.utils.translation.ugettext, 'Time')32 33 def test_no_warn_if_project_and_locale_paths_overlap(self):34 """Test that DeprecationWarning isn't generated when a deprecated project level locale/ subdir is also included in LOCALE_PATHS."""35 project_path = join(dirname(abspath(__file__)), '..')36 settings.LOCALE_PATHS += (normpath(join(project_path, 'locale')),)37 warnings.filterwarnings('error',38 "Translations in the project directory aren't supported anymore\. Use the LOCALE_PATHS setting instead\.",39 DeprecationWarning)40 _trans.__dict__ = {}41 try:42 django.utils.translation.ugettext('Time')43 except DeprecationWarning:44 self.fail("DeprecationWarning shouldn't be raised when settings/project locale and a LOCALE_PATHS member point to the same file system location.") -
tests/regressiontests/i18n/tests.py
diff --git a/tests/regressiontests/i18n/tests.py b/tests/regressiontests/i18n/tests.py
a b 40 40 URLTranslationTests, URLDisabledTests, URLTagTests, URLTestCaseBase, 41 41 URLRedirectWithoutTrailingSlashSettingTests, URLNamespaceTests, 42 42 URLPrefixTests, URLResponseTests, URLRedirectTests, PathUnusedTests) 43 from .test_warnings import DeprecationWarningTests44 43 45 44 46 45 here = os.path.dirname(os.path.abspath(__file__)) … … 869 868 with self.settings(INSTALLED_APPS=extended_apps): 870 869 self.assertUgettext('Time', 'LOCALE_PATHS') 871 870 872 def test_locale_paths_override_project_translation(self):873 with self.settings(SETTINGS_MODULE='regressiontests'):874 self.assertUgettext('Date/time', 'LOCALE_PATHS')875 876 class ProjectResolutionOrderI18NTests(ResolutionOrderI18NTests):877 878 def setUp(self):879 self.old_settings_module = settings.SETTINGS_MODULE880 settings.SETTINGS_MODULE = 'regressiontests'881 super(ProjectResolutionOrderI18NTests, self).setUp()882 883 def tearDown(self):884 settings.SETTINGS_MODULE = self.old_settings_module885 super(ProjectResolutionOrderI18NTests, self).tearDown()886 887 def test_project_translation(self):888 self.assertUgettext('Date/time', 'PROJECT')889 890 def test_project_override_app_translation(self):891 extended_apps = list(settings.INSTALLED_APPS) + ['regressiontests.i18n.resolution']892 with self.settings(INSTALLED_APPS=extended_apps):893 self.assertUgettext('Date/time', 'PROJECT')894 895 871 class DjangoFallbackResolutionOrderI18NTests(ResolutionOrderI18NTests): 896 872 897 873 def test_django_fallback(self): -
deleted file tests/regressiontests/locale/de/LC_MESSAGES/django.po
diff --git a/tests/regressiontests/locale/de/LC_MESSAGES/django.mo b/tests/regressiontests/locale/de/LC_MESSAGES/django.mo deleted file mode 100644 Binary file tests/regressiontests/locale/de/LC_MESSAGES/django.mo has changed diff --git a/tests/regressiontests/locale/de/LC_MESSAGES/django.po b/tests/regressiontests/locale/de/LC_MESSAGES/django.po deleted file mode 100644
+ - 1 # SOME DESCRIPTIVE TITLE.2 # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER3 # This file is distributed under the same license as the PACKAGE package.4 # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.5 #6 msgid ""7 msgstr ""8 "Project-Id-Version: django tests\n"9 "Report-Msgid-Bugs-To: \n"10 "POT-Creation-Date: 2010-02-14 17:33+0100\n"11 "PO-Revision-Date: 2011-02-07 13:13-0300\n"12 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"13 "Language-Team: LANGUAGE <LL@li.org>\n"14 "MIME-Version: 1.0\n"15 "Content-Type: text/plain; charset=UTF-8\n"16 "Content-Transfer-Encoding: 8bit\n"17 "Plural-Forms: nplurals=2; plural=(n != 1)\n"18 19 #: models.py:320 msgid "Time"21 msgstr "Zeit (PROJECT)"22 23 #: models.py:524 msgid "Date/time"25 msgstr "Datum/Zeit (PROJECT)" -
tests/runtests.py
diff --git a/tests/runtests.py b/tests/runtests.py
a b 25 25 TEMP_DIR = tempfile.mkdtemp(prefix='django_') 26 26 os.environ['DJANGO_TEST_TEMP_DIR'] = TEMP_DIR 27 27 28 REGRESSION_SUBDIRS_TO_SKIP = [ 'locale']28 REGRESSION_SUBDIRS_TO_SKIP = [] 29 29 30 30 ALWAYS_INSTALLED_APPS = [ 31 31 'django.contrib.contenttypes',