mirror of
				https://github.com/django/django.git
				synced 2025-10-31 09:41:08 +00:00 
			
		
		
		
	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
This commit is contained in:
		| @@ -155,9 +155,6 @@ def translation(language): | |||||||
|             if os.path.isdir(localepath): |             if os.path.isdir(localepath): | ||||||
|                 res = _merge(localepath) |                 res = _merge(localepath) | ||||||
|  |  | ||||||
|         if projectpath and os.path.isdir(projectpath): |  | ||||||
|             res = _merge(projectpath) |  | ||||||
|  |  | ||||||
|         for appname in settings.INSTALLED_APPS: |         for appname in settings.INSTALLED_APPS: | ||||||
|             app = import_module(appname) |             app = import_module(appname) | ||||||
|             apppath = os.path.join(os.path.dirname(app.__file__), 'locale') |             apppath = os.path.join(os.path.dirname(app.__file__), 'locale') | ||||||
| @@ -165,6 +162,9 @@ def translation(language): | |||||||
|             if os.path.isdir(apppath): |             if os.path.isdir(apppath): | ||||||
|                 res = _merge(apppath) |                 res = _merge(apppath) | ||||||
|  |  | ||||||
|  |         if projectpath and os.path.isdir(projectpath): | ||||||
|  |             res = _merge(projectpath) | ||||||
|  |  | ||||||
|         if res is None: |         if res is None: | ||||||
|             if fallback is not None: |             if fallback is not None: | ||||||
|                 res = fallback |                 res = fallback | ||||||
|   | |||||||
							
								
								
									
										
											BIN
										
									
								
								tests/regressiontests/i18n/other/locale/de/LC_MESSAGES/django.mo
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								tests/regressiontests/i18n/other/locale/de/LC_MESSAGES/django.mo
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| @@ -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)" | ||||||
							
								
								
									
										0
									
								
								tests/regressiontests/i18n/resolution/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								tests/regressiontests/i18n/resolution/__init__.py
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| @@ -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)" | ||||||
							
								
								
									
										1
									
								
								tests/regressiontests/i18n/resolution/models.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								tests/regressiontests/i18n/resolution/models.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1 @@ | |||||||
|  | # | ||||||
| @@ -1,4 +1,5 @@ | |||||||
| # -*- encoding: utf-8 -*- | # -*- encoding: utf-8 -*- | ||||||
|  | import os | ||||||
| import sys | import sys | ||||||
| import decimal | import decimal | ||||||
| import datetime | import datetime | ||||||
| @@ -497,3 +498,80 @@ class MiscTests(TestCase): | |||||||
|         r.COOKIES = {settings.LANGUAGE_COOKIE_NAME: 'zh-cn'} |         r.COOKIES = {settings.LANGUAGE_COOKIE_NAME: 'zh-cn'} | ||||||
|         r.META = {'HTTP_ACCEPT_LANGUAGE': 'de'} |         r.META = {'HTTP_ACCEPT_LANGUAGE': 'de'} | ||||||
|         self.assertEqual(g(r), 'zh-cn') |         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') | ||||||
|   | |||||||
							
								
								
									
										
											BIN
										
									
								
								tests/regressiontests/locale/de/LC_MESSAGES/django.mo
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								tests/regressiontests/locale/de/LC_MESSAGES/django.mo
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										22
									
								
								tests/regressiontests/locale/de/LC_MESSAGES/django.po
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								tests/regressiontests/locale/de/LC_MESSAGES/django.po
									
									
									
									
									
										Normal file
									
								
							| @@ -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)" | ||||||
| @@ -1,4 +1,3 @@ | |||||||
| from os import path |  | ||||||
| import gettext | import gettext | ||||||
|  |  | ||||||
| from django.conf import settings | from django.conf import settings | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user