diff --git a/django/utils/translation/trans_real.py b/django/utils/translation/trans_real.py index e6e0a61201..7a66177f30 100644 --- a/django/utils/translation/trans_real.py +++ b/django/utils/translation/trans_real.py @@ -155,9 +155,6 @@ def translation(language): 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 translation(language): 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 diff --git a/tests/regressiontests/i18n/other/locale/de/LC_MESSAGES/django.mo b/tests/regressiontests/i18n/other/locale/de/LC_MESSAGES/django.mo new file mode 100644 index 0000000000..2bc9343aa3 Binary files /dev/null and b/tests/regressiontests/i18n/other/locale/de/LC_MESSAGES/django.mo differ diff --git a/tests/regressiontests/i18n/other/locale/de/LC_MESSAGES/django.po b/tests/regressiontests/i18n/other/locale/de/LC_MESSAGES/django.po new file mode 100644 index 0000000000..2fdcee5015 --- /dev/null +++ b/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 , 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 \n" +"Language-Team: LANGUAGE \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)" diff --git a/tests/regressiontests/i18n/resolution/__init__.py b/tests/regressiontests/i18n/resolution/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/regressiontests/i18n/resolution/locale/de/LC_MESSAGES/django.mo b/tests/regressiontests/i18n/resolution/locale/de/LC_MESSAGES/django.mo new file mode 100644 index 0000000000..1c37ac5c87 Binary files /dev/null and b/tests/regressiontests/i18n/resolution/locale/de/LC_MESSAGES/django.mo differ diff --git a/tests/regressiontests/i18n/resolution/locale/de/LC_MESSAGES/django.po b/tests/regressiontests/i18n/resolution/locale/de/LC_MESSAGES/django.po new file mode 100644 index 0000000000..11d2d5d5ae --- /dev/null +++ b/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 , 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 \n" +"Language-Team: LANGUAGE \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)" diff --git a/tests/regressiontests/i18n/resolution/models.py b/tests/regressiontests/i18n/resolution/models.py new file mode 100644 index 0000000000..4287ca8617 --- /dev/null +++ b/tests/regressiontests/i18n/resolution/models.py @@ -0,0 +1 @@ +# \ No newline at end of file diff --git a/tests/regressiontests/i18n/tests.py b/tests/regressiontests/i18n/tests.py index 588a7b607c..a4d0d90400 100644 --- a/tests/regressiontests/i18n/tests.py +++ b/tests/regressiontests/i18n/tests.py @@ -1,4 +1,5 @@ # -*- encoding: utf-8 -*- +import os import sys import decimal import datetime @@ -497,3 +498,80 @@ class MiscTests(TestCase): 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') diff --git a/tests/regressiontests/locale/de/LC_MESSAGES/django.mo b/tests/regressiontests/locale/de/LC_MESSAGES/django.mo new file mode 100644 index 0000000000..2ee860a80b Binary files /dev/null and b/tests/regressiontests/locale/de/LC_MESSAGES/django.mo differ diff --git a/tests/regressiontests/locale/de/LC_MESSAGES/django.po b/tests/regressiontests/locale/de/LC_MESSAGES/django.po new file mode 100644 index 0000000000..356e3d3246 --- /dev/null +++ b/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 , 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 \n" +"Language-Team: LANGUAGE \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)" diff --git a/tests/regressiontests/views/tests/i18n.py b/tests/regressiontests/views/tests/i18n.py index a6b0b89389..7debb213f6 100644 --- a/tests/regressiontests/views/tests/i18n.py +++ b/tests/regressiontests/views/tests/i18n.py @@ -1,4 +1,3 @@ -from os import path import gettext from django.conf import settings