Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

unicode: Renamed no_trans() to the more descriptive deactivate_all().…

… Added a

verbose_name_raw attribute to the model Options class so that we can more
conveniently access the untranslated model name when we need to.


git-svn-id: http://code.djangoproject.com/svn/django/branches/unicode@5255 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit abf514053b5097d3071a8a282cadbb4bbb73fe87 1 parent 267dcdb
Malcolm Tredinnick malcolmt authored
6 django/contrib/contenttypes/management.py
View
@@ -4,7 +4,6 @@
from django.dispatch import dispatcher
from django.db.models import get_apps, get_models, signals
-from django.utils.translation import activate, no_trans, get_language
from django.utils.encoding import smart_unicode
def create_contenttypes(app, created_models, verbosity=2):
@@ -19,12 +18,9 @@ def create_contenttypes(app, created_models, verbosity=2):
ContentType.objects.get(app_label=opts.app_label,
model=opts.object_name.lower())
except ContentType.DoesNotExist:
- lang = get_language()
- no_trans()
- ct = ContentType(name=smart_unicode(opts.verbose_name),
+ ct = ContentType(name=smart_unicode(opts.verbose_name_raw),
app_label=opts.app_label, model=opts.object_name.lower())
ct.save()
- activate(lang)
if verbosity >= 2:
print "Adding content type '%s | %s'" % (ct.app_label, ct.model)
7 django/contrib/contenttypes/models.py
View
@@ -1,5 +1,5 @@
from django.db import models
-from django.utils.translation import ugettext_lazy as _, no_trans, activate, get_language
+from django.utils.translation import ugettext_lazy as _
from django.utils.encoding import smart_unicode
CONTENT_TYPE_CACHE = {}
@@ -16,12 +16,9 @@ def get_for_model(self, model):
except KeyError:
# The unicode() is needed around opts.verbose_name because it might
# be a django.utils.functional.__proxy__ object.
- lang = get_language()
- no_trans()
ct, created = self.model._default_manager.get_or_create(app_label=key[0],
- model=key[1], defaults={'name': smart_unicode(opts.verbose_name)})
+ model=key[1], defaults={'name': smart_unicode(opts.verbose_name_raw)})
CONTENT_TYPE_CACHE[key] = ct
- activate(lang)
return ct
def clear_cache(self):
10 django/db/models/options.py
View
@@ -5,6 +5,7 @@
from django.db.models.loading import get_models
from django.db.models.query import orderlist2sql
from django.db.models import Manager
+from django.utils.translation import activate, deactivate_all, get_language
from bisect import bisect
import re
@@ -41,6 +42,15 @@ def contribute_to_class(self, cls, name):
self.object_name = cls.__name__
self.module_name = self.object_name.lower()
self.verbose_name = get_verbose_name(self.object_name)
+
+ # There are a few places where the untranslated verbose name is needed
+ # (so that we get the same value regardless of currently active
+ # locale).
+ lang = get_language()
+ deactivate_all()
+ self.verbose_name_raw = unicode(self.verbose_name)
+ activate(lang)
+
# Next, apply any overridden values from 'class Meta'.
if self.meta:
meta_attrs = self.meta.__dict__
6 django/utils/translation/__init__.py
View
@@ -8,7 +8,7 @@
'get_language', 'get_language_bidi', 'get_date_formats',
'get_partial_date_formats', 'check_for_language', 'to_locale',
'get_language_from_request', 'install', 'templatize', 'ugettext',
- 'ungettext', 'no_trans']
+ 'ungettext', 'deactivate_all']
# Here be dragons, so a short explanation of the logic won't hurt:
# We are trying to solve two problems: (1) access settings, in particular
@@ -105,6 +105,6 @@ def install():
def templatize(src):
return real_templatize(src)
-def no_trans():
- return real_no_trans()
+def deactivate_all():
+ return real_deactivate_all()
2  django/utils/translation/trans_null.py
View
@@ -15,7 +15,7 @@ def ungettext(singular, plural, number):
string_concat = lambda *strings: ''.join([str(el) for el in strings])
activate = lambda x: None
-deactivate = no_trans = install = lambda: None
+deactivate = deactivate_all = install = lambda: None
get_language = lambda: settings.LANGUAGE_CODE
get_language_bidi = lambda: settings.LANGUAGE_CODE in settings.LANGUAGES_BIDI
get_date_formats = lambda: (settings.DATE_FORMAT, settings.DATETIME_FORMAT, settings.TIME_FORMAT)
2  django/utils/translation/trans_real.py
View
@@ -203,7 +203,7 @@ def deactivate():
if currentThread() in _active:
del _active[currentThread()]
-def no_trans():
+def deactivate_all():
"""
Makes the active translation object a NullTranslations() instance. This is
useful when we want delayed translations to appear as the original string
Please sign in to comment.
Something went wrong with that request. Please try again.