diff -r 275034865933 django/utils/translation/trans_real.py
|
a
|
b
|
|
| 79 | 79 | self.__language = '??' |
| 80 | 80 | |
| 81 | 81 | 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 |
| 83 | 85 | |
| 84 | 86 | def set_language(self, language): |
| 85 | 87 | self.__language = language |
| … |
… |
|
| 138 | 140 | except IOError, e: |
| 139 | 141 | return None |
| 140 | 142 | |
| 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 | | |
| 152 | 143 | def _merge(path): |
| 153 | 144 | t = _translation(path) |
| 154 | 145 | if t is not None: |
| 155 | 146 | 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() |
| 156 | 156 | return t |
| 157 | 157 | else: |
| 158 | 158 | res.merge(t) |
| 159 | 159 | return res |
| 160 | 160 | |
| 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) |
| 164 | 163 | |
| 165 | 164 | for appname in settings.INSTALLED_APPS: |
| 166 | 165 | app = import_module(appname) |
| … |
… |
|
| 169 | 168 | if os.path.isdir(apppath): |
| 170 | 169 | res = _merge(apppath) |
| 171 | 170 | |
| 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) |
| 174 | 176 | |
| 175 | 177 | if res is None: |
| 176 | 178 | if fallback is not None: |