diff options
| author | Ramiro Morales <cramm0@gmail.com> | 2011-02-07 18:48:40 +0000 |
|---|---|---|
| committer | Ramiro Morales <cramm0@gmail.com> | 2011-02-07 18:48:40 +0000 |
| commit | f6e38f3800f769b6f03799a1792b2cb1a9f42c32 (patch) | |
| tree | 7d0dc9d736fa664a4fdf9ebd5ae2ae0fcbbe01af /django/utils/translation/__init__.py | |
| parent | 5718a678e53be46d90d5bc07519907d317908928 (diff) | |
Fixed #5494, #10765, #14924 -- Modified the order in which translations are read when composing the final translation to offer at runtime.
This is slightly backward-incompatible (could result in changed final translations for literals appearing multiple times in different .po files but with different translations).
Translations are now read in the following order (from lower to higher priority):
For the 'django' gettext domain:
* Django translations
* INSTALLED_APPS apps translations (with the ones listed first having higher priority)
* settings/project path translations (deprecated, see below)
* LOCALE_PATHS translations (with the ones listed first having higher priority)
For the 'djangojs' gettext domain:
* Python modules whose names are passed to the javascript_catalog view
* LOCALE_PATHS translations (with the ones listed first having higher priority, previously they weren't included)
Also, automatic loading of translations from the 'locale' subdir of the settings/project path is now deprecated.
Thanks to vanschelven, vbmendes and an anonymous user for reporting issues, to vanschelven, Claude Paroz and an anonymous contributor for their initial work on fixes and to Jannis Leidel and Claude for review and discussion.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@15441 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/utils/translation/__init__.py')
| -rw-r--r-- | django/utils/translation/__init__.py | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/django/utils/translation/__init__.py b/django/utils/translation/__init__.py index aaae284e5a..e44b556c16 100644 --- a/django/utils/translation/__init__.py +++ b/django/utils/translation/__init__.py @@ -1,8 +1,11 @@ """ Internationalization support. """ +from os import path + from django.utils.encoding import force_unicode -from django.utils.functional import lazy, curry +from django.utils.functional import lazy +from django.utils.importlib import import_module __all__ = ['gettext', 'gettext_noop', 'gettext_lazy', 'ngettext', @@ -33,10 +36,22 @@ class Trans(object): performance effect, as access to the function goes the normal path, instead of using __getattr__. """ + def __getattr__(self, real_name): from django.conf import settings if settings.USE_I18N: from django.utils.translation import trans_real as trans + + if settings.SETTINGS_MODULE is not None: + import warnings + parts = settings.SETTINGS_MODULE.split('.') + project = import_module(parts[0]) + if path.isdir(path.join(path.dirname(project.__file__), 'locale')): + warnings.warn( + "Translations in the project directory aren't supported anymore. Use the LOCALE_PATHS setting instead.", + PendingDeprecationWarning + ) + else: from django.utils.translation import trans_null as trans setattr(self, real_name, getattr(trans, real_name)) |
