Code

Ticket #11105: translate_permissions.diff

File translate_permissions.diff, 1.6 KB (added by hcarvalhoalves, 5 years ago)

Fix for this particular case - just to keep track

Line 
1--- django/contrib/auth/management/__init__.py  2009-05-13 18:32:02.000000000 -0300
2+++ fix.py      2009-05-13 18:31:57.000000000 -0300
3@@ -4,6 +4,9 @@
4 
5 from django.db.models import get_models, signals
6 from django.contrib.auth import models as auth_app
7+from django.utils.translation import ugettext as _
8+from django.utils.encoding import force_unicode
9+
10 
11 def _get_permission_codename(action, opts):
12     return u'%s_%s' % (action, opts.object_name.lower())
13@@ -11,13 +14,22 @@
14 def _get_all_permissions(opts):
15     "Returns (codename, name) for all permissions in the given opts."
16     perms = []
17-    for action in ('add', 'change', 'delete'):
18-        perms.append((_get_permission_codename(action, opts), u'Can %s %s' % (action, opts.verbose_name_raw)))
19+    default_actions = (
20+        ('add', _(u'Can add %(name)s') % {'name': opts.verbose_name_raw}),
21+        ('change', _(u'Can change %(name)s') % {'name': opts.verbose_name_raw}),
22+        ('delete', _(u'Can delete %(name)s') % {'name': opts.verbose_name_raw}),
23+    )
24+    for action, name in default_actions:
25+        perms.append((_get_permission_codename(action, opts),
26+            force_unicode(name)))
27     return perms + list(opts.permissions)
28 
29 def create_permissions(app, created_models, verbosity, **kwargs):
30     from django.contrib.contenttypes.models import ContentType
31     from django.contrib.auth.models import Permission
32+    from django.utils.translation import activate
33+    from django.conf import settings
34+    activate(settings.LANGUAGE_CODE)
35     app_models = get_models(app)
36     if not app_models:
37         return