Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #11384 - Make sure translations in the project directory really…

… override translations in apps as specified in the docs.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@12447 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 12d40a9fd63d1b92d7410f8fec8adc69980daee0 1 parent 16942e1
@jezdez jezdez authored
View
6 django/utils/translation/trans_real.py
@@ -155,9 +155,6 @@ def _merge(path):
if os.path.isdir(localepath):
res = _merge(localepath)
- if projectpath and os.path.isdir(projectpath):
- res = _merge(projectpath)
-
for appname in settings.INSTALLED_APPS:
app = import_module(appname)
apppath = os.path.join(os.path.dirname(app.__file__), 'locale')
@@ -165,6 +162,9 @@ def _merge(path):
if os.path.isdir(apppath):
res = _merge(apppath)
+ if projectpath and os.path.isdir(projectpath):
+ res = _merge(projectpath)
+
if res is None:
if fallback is not None:
res = fallback
View
BIN  tests/regressiontests/i18n/other/locale/de/LC_MESSAGES/django.mo
Binary file not shown
View
22 tests/regressiontests/i18n/other/locale/de/LC_MESSAGES/django.po
@@ -0,0 +1,22 @@
+# 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: 2010-02-14 17:33+0100\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\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"
+"Plural-Forms: nplurals=2; plural=(n != 1)\n"
+
+#: models.py:3
+msgid "Date/time"
+msgstr "Datum/Zeit (LOCALE_PATHS)"
View
0  tests/regressiontests/i18n/resolution/__init__.py
No changes.
View
BIN  tests/regressiontests/i18n/resolution/locale/de/LC_MESSAGES/django.mo
Binary file not shown
View
22 tests/regressiontests/i18n/resolution/locale/de/LC_MESSAGES/django.po
@@ -0,0 +1,22 @@
+# 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: 2010-02-14 17:33+0100\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\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"
+"Plural-Forms: nplurals=2; plural=(n != 1)\n"
+
+#: models.py:3
+msgid "Date/time"
+msgstr "Datum/Zeit (APP)"
View
1  tests/regressiontests/i18n/resolution/models.py
@@ -0,0 +1 @@
+#
View
78 tests/regressiontests/i18n/tests.py
@@ -1,4 +1,5 @@
# -*- encoding: utf-8 -*-
+import os
import sys
import decimal
import datetime
@@ -497,3 +498,80 @@ def test_parse_language_cookie(self):
r.COOKIES = {settings.LANGUAGE_COOKIE_NAME: 'zh-cn'}
r.META = {'HTTP_ACCEPT_LANGUAGE': 'de'}
self.assertEqual(g(r), 'zh-cn')
+
+class ResolutionOrderI18NTests(TestCase):
+
+ def setUp(self):
+ from django.utils.translation import trans_real
+ # Okay, this is brutal, but we have no other choice to fully reset
+ # the translation framework
+ trans_real._active = {}
+ trans_real._translations = {}
+ activate('de')
+
+ def tearDown(self):
+ deactivate()
+
+ def assertUgettext(self, msgid, msgstr):
+ result = ugettext(msgid)
+ self.assert_(msgstr in result, ("The string '%s' isn't in the "
+ "translation of '%s'; the actual result is '%s'." % (msgstr, msgid, result)))
+
+class AppResolutionOrderI18NTests(ResolutionOrderI18NTests):
+
+ def setUp(self):
+ self.old_installed_apps = settings.INSTALLED_APPS
+ settings.INSTALLED_APPS = list(settings.INSTALLED_APPS) + ['regressiontests.i18n.resolution']
+ super(AppResolutionOrderI18NTests, self).setUp()
+
+ def tearDown(self):
+ settings.INSTALLED_APPS = self.old_installed_apps
+ super(AppResolutionOrderI18NTests, self).tearDown()
+
+ def test_app_translation(self):
+ self.assertUgettext('Date/time', 'APP')
+
+class LocalePathsResolutionOrderI18NTests(ResolutionOrderI18NTests):
+
+ def setUp(self):
+ self.old_locale_paths = settings.LOCALE_PATHS
+ settings.LOCALE_PATHS += (os.path.join(os.path.dirname(os.path.abspath(__file__)), 'other', 'locale'),)
+ super(LocalePathsResolutionOrderI18NTests, self).setUp()
+
+ def tearDown(self):
+ settings.LOCALE_PATHS = self.old_locale_paths
+ super(LocalePathsResolutionOrderI18NTests, self).tearDown()
+
+ def test_locale_paths_translation(self):
+ self.assertUgettext('Date/time', 'LOCALE_PATHS')
+
+class ProjectResolutionOrderI18NTests(ResolutionOrderI18NTests):
+
+ def setUp(self):
+ self.old_settings_module = settings.SETTINGS_MODULE
+ settings.SETTINGS_MODULE = 'regressiontests'
+ super(ProjectResolutionOrderI18NTests, self).setUp()
+
+ def tearDown(self):
+ settings.SETTINGS_MODULE = self.old_settings_module
+ super(ProjectResolutionOrderI18NTests, self).tearDown()
+
+ def test_project_translation(self):
+ self.assertUgettext('Date/time', 'PROJECT')
+
+ def test_project_override_app_translation(self):
+ old_installed_apps = settings.INSTALLED_APPS
+ settings.INSTALLED_APPS = list(settings.INSTALLED_APPS) + ['regressiontests.i18n.resolution']
+ self.assertUgettext('Date/time', 'PROJECT')
+ settings.INSTALLED_APPS = old_installed_apps
+
+ def test_project_override_locale_paths_translation(self):
+ old_locale_paths = settings.LOCALE_PATHS
+ settings.LOCALE_PATHS += (os.path.join(os.path.dirname(os.path.abspath(__file__)), 'other', 'locale'),)
+ self.assertUgettext('Date/time', 'PROJECT')
+ settings.LOCALE_PATHS = old_locale_paths
+
+class DjangoFallbackResolutionOrderI18NTests(ResolutionOrderI18NTests):
+
+ def test_django_fallback(self):
+ self.assertUgettext('Date/time', 'Datum/Zeit')
View
BIN  tests/regressiontests/locale/de/LC_MESSAGES/django.mo
Binary file not shown
View
22 tests/regressiontests/locale/de/LC_MESSAGES/django.po
@@ -0,0 +1,22 @@
+# 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: 2010-02-14 17:33+0100\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\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"
+"Plural-Forms: nplurals=2; plural=(n != 1)\n"
+
+#: models.py:3
+msgid "Date/time"
+msgstr "Datum/Zeit (PROJECT)"
View
1  tests/regressiontests/views/tests/i18n.py
@@ -1,4 +1,3 @@
-from os import path
import gettext
from django.conf import settings
Please sign in to comment.
Something went wrong with that request. Please try again.