Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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 authored May 16, 2007
6  django/contrib/contenttypes/management.py
@@ -4,7 +4,6 @@
4 4
 
5 5
 from django.dispatch import dispatcher
6 6
 from django.db.models import get_apps, get_models, signals
7  
-from django.utils.translation import activate, no_trans, get_language
8 7
 from django.utils.encoding import smart_unicode
9 8
 
10 9
 def create_contenttypes(app, created_models, verbosity=2):
@@ -19,12 +18,9 @@ def create_contenttypes(app, created_models, verbosity=2):
19 18
             ContentType.objects.get(app_label=opts.app_label,
20 19
                 model=opts.object_name.lower())
21 20
         except ContentType.DoesNotExist:
22  
-            lang = get_language()
23  
-            no_trans()
24  
-            ct = ContentType(name=smart_unicode(opts.verbose_name),
  21
+            ct = ContentType(name=smart_unicode(opts.verbose_name_raw),
25 22
                 app_label=opts.app_label, model=opts.object_name.lower())
26 23
             ct.save()
27  
-            activate(lang)
28 24
             if verbosity >= 2:
29 25
                 print "Adding content type '%s | %s'" % (ct.app_label, ct.model)
30 26
 
7  django/contrib/contenttypes/models.py
... ...
@@ -1,5 +1,5 @@
1 1
 from django.db import models
2  
-from django.utils.translation import ugettext_lazy as _, no_trans, activate, get_language
  2
+from django.utils.translation import ugettext_lazy as _
3 3
 from django.utils.encoding import smart_unicode
4 4
 
5 5
 CONTENT_TYPE_CACHE = {}
@@ -16,12 +16,9 @@ def get_for_model(self, model):
16 16
         except KeyError:
17 17
             # The unicode() is needed around opts.verbose_name because it might
18 18
             # be a django.utils.functional.__proxy__ object.
19  
-            lang = get_language()
20  
-            no_trans()
21 19
             ct, created = self.model._default_manager.get_or_create(app_label=key[0],
22  
-                model=key[1], defaults={'name': smart_unicode(opts.verbose_name)})
  20
+                model=key[1], defaults={'name': smart_unicode(opts.verbose_name_raw)})
23 21
             CONTENT_TYPE_CACHE[key] = ct
24  
-            activate(lang)
25 22
         return ct
26 23
 
27 24
     def clear_cache(self):
10  django/db/models/options.py
@@ -5,6 +5,7 @@
5 5
 from django.db.models.loading import get_models
6 6
 from django.db.models.query import orderlist2sql
7 7
 from django.db.models import Manager
  8
+from django.utils.translation import activate, deactivate_all, get_language
8 9
 from bisect import bisect
9 10
 import re
10 11
 
@@ -41,6 +42,15 @@ def contribute_to_class(self, cls, name):
41 42
         self.object_name = cls.__name__
42 43
         self.module_name = self.object_name.lower()
43 44
         self.verbose_name = get_verbose_name(self.object_name)
  45
+
  46
+        # There are a few places where the untranslated verbose name is needed
  47
+        # (so that we get the same value regardless of currently active
  48
+        # locale).
  49
+        lang = get_language()
  50
+        deactivate_all()
  51
+        self.verbose_name_raw = unicode(self.verbose_name)
  52
+        activate(lang)
  53
+
44 54
         # Next, apply any overridden values from 'class Meta'.
45 55
         if self.meta:
46 56
             meta_attrs = self.meta.__dict__
6  django/utils/translation/__init__.py
@@ -8,7 +8,7 @@
8 8
         'get_language', 'get_language_bidi', 'get_date_formats',
9 9
         'get_partial_date_formats', 'check_for_language', 'to_locale',
10 10
         'get_language_from_request', 'install', 'templatize', 'ugettext',
11  
-        'ungettext', 'no_trans']
  11
+        'ungettext', 'deactivate_all']
12 12
 
13 13
 # Here be dragons, so a short explanation of the logic won't hurt:
14 14
 # We are trying to solve two problems: (1) access settings, in particular
@@ -105,6 +105,6 @@ def install():
105 105
 def templatize(src):
106 106
     return real_templatize(src)
107 107
 
108  
-def no_trans():
109  
-    return real_no_trans()
  108
+def deactivate_all():
  109
+    return real_deactivate_all()
110 110
 
2  django/utils/translation/trans_null.py
@@ -15,7 +15,7 @@ def ungettext(singular, plural, number):
15 15
 
16 16
 string_concat = lambda *strings: ''.join([str(el) for el in strings])
17 17
 activate = lambda x: None
18  
-deactivate = no_trans = install = lambda: None
  18
+deactivate = deactivate_all = install = lambda: None
19 19
 get_language = lambda: settings.LANGUAGE_CODE
20 20
 get_language_bidi = lambda: settings.LANGUAGE_CODE in settings.LANGUAGES_BIDI
21 21
 get_date_formats = lambda: (settings.DATE_FORMAT, settings.DATETIME_FORMAT, settings.TIME_FORMAT)
2  django/utils/translation/trans_real.py
@@ -203,7 +203,7 @@ def deactivate():
203 203
     if currentThread() in _active:
204 204
         del _active[currentThread()]
205 205
 
206  
-def no_trans():
  206
+def deactivate_all():
207 207
     """
208 208
     Makes the active translation object a NullTranslations() instance. This is
209 209
     useful when we want delayed translations to appear as the original string

0 notes on commit abf5140

Please sign in to comment.
Something went wrong with that request. Please try again.