Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
Jannis Leidel authored February 16, 2010
6  django/utils/translation/trans_real.py
@@ -155,9 +155,6 @@ def _merge(path):
155 155
             if os.path.isdir(localepath):
156 156
                 res = _merge(localepath)
157 157
 
158  
-        if projectpath and os.path.isdir(projectpath):
159  
-            res = _merge(projectpath)
160  
-
161 158
         for appname in settings.INSTALLED_APPS:
162 159
             app = import_module(appname)
163 160
             apppath = os.path.join(os.path.dirname(app.__file__), 'locale')
@@ -165,6 +162,9 @@ def _merge(path):
165 162
             if os.path.isdir(apppath):
166 163
                 res = _merge(apppath)
167 164
 
  165
+        if projectpath and os.path.isdir(projectpath):
  166
+            res = _merge(projectpath)
  167
+
168 168
         if res is None:
169 169
             if fallback is not None:
170 170
                 res = fallback
BIN  tests/regressiontests/i18n/other/locale/de/LC_MESSAGES/django.mo
Binary file not shown
22  tests/regressiontests/i18n/other/locale/de/LC_MESSAGES/django.po
... ...
@@ -0,0 +1,22 @@
  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: 2010-02-14 17:33+0100\n"
  12
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\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"
  18
+"Plural-Forms: nplurals=2; plural=(n != 1)\n"
  19
+
  20
+#: models.py:3
  21
+msgid "Date/time"
  22
+msgstr "Datum/Zeit (LOCALE_PATHS)"
0  tests/regressiontests/i18n/resolution/__init__.py
No changes.
BIN  tests/regressiontests/i18n/resolution/locale/de/LC_MESSAGES/django.mo
Binary file not shown
22  tests/regressiontests/i18n/resolution/locale/de/LC_MESSAGES/django.po
... ...
@@ -0,0 +1,22 @@
  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: 2010-02-14 17:33+0100\n"
  12
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\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"
  18
+"Plural-Forms: nplurals=2; plural=(n != 1)\n"
  19
+
  20
+#: models.py:3
  21
+msgid "Date/time"
  22
+msgstr "Datum/Zeit (APP)"
1  tests/regressiontests/i18n/resolution/models.py
... ...
@@ -0,0 +1 @@
  1
+#
78  tests/regressiontests/i18n/tests.py
... ...
@@ -1,4 +1,5 @@
1 1
 # -*- encoding: utf-8 -*-
  2
+import os
2 3
 import sys
3 4
 import decimal
4 5
 import datetime
@@ -497,3 +498,80 @@ def test_parse_language_cookie(self):
497 498
         r.COOKIES = {settings.LANGUAGE_COOKIE_NAME: 'zh-cn'}
498 499
         r.META = {'HTTP_ACCEPT_LANGUAGE': 'de'}
499 500
         self.assertEqual(g(r), 'zh-cn')
  501
+
  502
+class ResolutionOrderI18NTests(TestCase):
  503
+
  504
+    def setUp(self):
  505
+        from django.utils.translation import trans_real
  506
+        # Okay, this is brutal, but we have no other choice to fully reset
  507
+        # the translation framework
  508
+        trans_real._active = {}
  509
+        trans_real._translations = {}
  510
+        activate('de')
  511
+
  512
+    def tearDown(self):
  513
+        deactivate()
  514
+
  515
+    def assertUgettext(self, msgid, msgstr):
  516
+        result = ugettext(msgid)
  517
+        self.assert_(msgstr in result, ("The string '%s' isn't in the "
  518
+            "translation of '%s'; the actual result is '%s'." % (msgstr, msgid, result)))
  519
+
  520
+class AppResolutionOrderI18NTests(ResolutionOrderI18NTests):
  521
+
  522
+    def setUp(self):
  523
+        self.old_installed_apps = settings.INSTALLED_APPS
  524
+        settings.INSTALLED_APPS = list(settings.INSTALLED_APPS) + ['regressiontests.i18n.resolution']
  525
+        super(AppResolutionOrderI18NTests, self).setUp()
  526
+
  527
+    def tearDown(self):
  528
+        settings.INSTALLED_APPS = self.old_installed_apps
  529
+        super(AppResolutionOrderI18NTests, self).tearDown()
  530
+
  531
+    def test_app_translation(self):
  532
+        self.assertUgettext('Date/time', 'APP')
  533
+
  534
+class LocalePathsResolutionOrderI18NTests(ResolutionOrderI18NTests):
  535
+
  536
+    def setUp(self):
  537
+        self.old_locale_paths = settings.LOCALE_PATHS
  538
+        settings.LOCALE_PATHS += (os.path.join(os.path.dirname(os.path.abspath(__file__)), 'other', 'locale'),)
  539
+        super(LocalePathsResolutionOrderI18NTests, self).setUp()
  540
+
  541
+    def tearDown(self):
  542
+        settings.LOCALE_PATHS = self.old_locale_paths
  543
+        super(LocalePathsResolutionOrderI18NTests, self).tearDown()
  544
+
  545
+    def test_locale_paths_translation(self):
  546
+        self.assertUgettext('Date/time', 'LOCALE_PATHS')
  547
+
  548
+class ProjectResolutionOrderI18NTests(ResolutionOrderI18NTests):
  549
+
  550
+    def setUp(self):
  551
+        self.old_settings_module = settings.SETTINGS_MODULE
  552
+        settings.SETTINGS_MODULE = 'regressiontests'
  553
+        super(ProjectResolutionOrderI18NTests, self).setUp()
  554
+
  555
+    def tearDown(self):
  556
+        settings.SETTINGS_MODULE = self.old_settings_module
  557
+        super(ProjectResolutionOrderI18NTests, self).tearDown()
  558
+
  559
+    def test_project_translation(self):
  560
+        self.assertUgettext('Date/time', 'PROJECT')
  561
+
  562
+    def test_project_override_app_translation(self):
  563
+        old_installed_apps = settings.INSTALLED_APPS
  564
+        settings.INSTALLED_APPS = list(settings.INSTALLED_APPS) + ['regressiontests.i18n.resolution']
  565
+        self.assertUgettext('Date/time', 'PROJECT')
  566
+        settings.INSTALLED_APPS = old_installed_apps
  567
+
  568
+    def test_project_override_locale_paths_translation(self):
  569
+        old_locale_paths = settings.LOCALE_PATHS
  570
+        settings.LOCALE_PATHS += (os.path.join(os.path.dirname(os.path.abspath(__file__)), 'other', 'locale'),)
  571
+        self.assertUgettext('Date/time', 'PROJECT')
  572
+        settings.LOCALE_PATHS = old_locale_paths
  573
+
  574
+class DjangoFallbackResolutionOrderI18NTests(ResolutionOrderI18NTests):
  575
+
  576
+    def test_django_fallback(self):
  577
+        self.assertUgettext('Date/time', 'Datum/Zeit')
BIN  tests/regressiontests/locale/de/LC_MESSAGES/django.mo
Binary file not shown
22  tests/regressiontests/locale/de/LC_MESSAGES/django.po
... ...
@@ -0,0 +1,22 @@
  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: 2010-02-14 17:33+0100\n"
  12
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\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"
  18
+"Plural-Forms: nplurals=2; plural=(n != 1)\n"
  19
+
  20
+#: models.py:3
  21
+msgid "Date/time"
  22
+msgstr "Datum/Zeit (PROJECT)"
1  tests/regressiontests/views/tests/i18n.py
... ...
@@ -1,4 +1,3 @@
1  
-from os import path
2 1
 import gettext
3 2
 
4 3
 from django.conf import settings

0 notes on commit 12d40a9

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