Ticket #14924: with_test.patch

File with_test.patch, 5.3 KB (added by Klaas van Schelven, 13 years ago)

Patch with test.

  • django/utils/translation/trans_real.py

    diff -r 275034865933 django/utils/translation/trans_real.py
    a b  
    7979        self.__language = '??'
    8080
    8181    def merge(self, other):
    82         self._catalog.update(other._catalog)
     82        for k, v in other._catalog.items():
     83            if k not in self._catalog:
     84                self._catalog[k] = v
    8385
    8486    def set_language(self, language):
    8587        self.__language = language
     
    138140            except IOError, e:
    139141                return None
    140142
    141         res = _translation(globalpath)
    142 
    143         # We want to ensure that, for example,  "en-gb" and "en-us" don't share
    144         # the same translation object (thus, merging en-us with a local update
    145         # doesn't affect en-gb), even though they will both use the core "en"
    146         # translation. So we have to subvert Python's internal gettext caching.
    147         base_lang = lambda x: x.split('-', 1)[0]
    148         if base_lang(lang) in [base_lang(trans) for trans in _translations]:
    149             res._info = res._info.copy()
    150             res._catalog = res._catalog.copy()
    151 
    152143        def _merge(path):
    153144            t = _translation(path)
    154145            if t is not None:
    155146                if res is None:
     147                    # We want to ensure that, for example,  "en-gb" and "en-us" don't share
     148                    # the same translation object (thus, merging en-us with a local update
     149                    # doesn't affect en-gb), even though they will both use the core "en"
     150                    # translation. So we have to subvert Python's internal gettext caching.
     151
     152                    base_lang = lambda x: x.split('-', 1)[0]
     153                    if base_lang(lang) in [base_lang(trans) for trans in _translations]:
     154                        t._info = t._info.copy()
     155                        t._catalog = t._catalog.copy()
    156156                    return t
    157157                else:
    158158                    res.merge(t)
    159159            return res
    160160
    161         for localepath in settings.LOCALE_PATHS:
    162             if os.path.isdir(localepath):
    163                 res = _merge(localepath)
     161        if projectpath and os.path.isdir(projectpath):
     162            res = _merge(projectpath)
    164163
    165164        for appname in settings.INSTALLED_APPS:
    166165            app = import_module(appname)
     
    169168            if os.path.isdir(apppath):
    170169                res = _merge(apppath)
    171170
    172         if projectpath and os.path.isdir(projectpath):
    173             res = _merge(projectpath)
     171        for localepath in settings.LOCALE_PATHS:
     172            if os.path.isdir(localepath):
     173                res = _merge(localepath)
     174
     175        res = _merge(globalpath)
    174176
    175177        if res is None:
    176178            if fallback is not None:
  • tests/regressiontests/i18n/resolution_high_priority/locale/de/LC_MESSAGES/django.po

    diff -r 275034865933 tests/regressiontests/i18n/resolution_high_priority/locale/de/LC_MESSAGES/django.mo
    Binary file tests/regressiontests/i18n/resolution_high_priority/locale/de/LC_MESSAGES/django.mo has changed
    diff -r 275034865933 tests/regressiontests/i18n/resolution_high_priority/locale/de/LC_MESSAGES/django.po
    a b  
     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
     7msgid ""
     8msgstr ""
     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
     21msgid "Date/time"
     22msgstr "Datum/Zeit (FIRST APP)"
  • b/tests/regressiontests/i18n/resolution_high_priority/models.py

    diff -r 275034865933 tests/regressiontests/i18n/resolution_high_priority/models.py
     
     1#
     2 No newline at end of file
  • tests/regressiontests/i18n/tests.py

    diff -r 275034865933 tests/regressiontests/i18n/tests.py
    a b  
    654654    def test_app_translation(self):
    655655        self.assertUgettext('Date/time', 'APP')
    656656
     657class AppResolutionOrderI18NTests(ResolutionOrderI18NTests):
     658
     659    def setUp(self):
     660        self.old_installed_apps = settings.INSTALLED_APPS
     661        settings.INSTALLED_APPS = list(settings.INSTALLED_APPS) + ['regressiontests.i18n.resolution_high_priority', 'regressiontests.i18n.resolution']
     662        super(AppResolutionOrderI18NTests, self).setUp()
     663
     664    def tearDown(self):
     665        settings.INSTALLED_APPS = self.old_installed_apps
     666        super(AppResolutionOrderI18NTests, self).tearDown()
     667
     668    def test_app_translation(self):
     669        self.assertUgettext('Date/time', 'FIRST APP')
     670
    657671class LocalePathsResolutionOrderI18NTests(ResolutionOrderI18NTests):
    658672
    659673    def setUp(self):
Back to Top