Ticket #14910: trans_real.patch

File trans_real.patch, 2.8 KB (added by Klaas van Schelven, 14 years ago)
  • 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:
Back to Top