Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added translation strings to django/core/meta/fields.py. Taken from n…

…ew-admin.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@1423 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 807b406859653f1737865276a2bb796ab3809453 1 parent 9898c4a
Adrian Holovaty authored

Showing 1 changed file with 12 additions and 11 deletions. Show diff stats Hide diff stats

  1. 23  django/core/meta/fields.py
23  django/core/meta/fields.py
@@ -3,7 +3,7 @@
3 3
 from django.core.exceptions import ObjectDoesNotExist
4 4
 from django.utils.functional import curry, lazy
5 5
 from django.utils.text import capfirst
6  
-from django.utils.translation import gettext_lazy
  6
+from django.utils.translation import gettext_lazy, ngettext
7 7
 import datetime, os
8 8
 
9 9
 # Random entropy string used by "default" param.
@@ -43,7 +43,7 @@ def manipulator_valid_rel_key(f, self, field_data, all_data):
43 43
     try:
44 44
         mod.get_object(pk=field_data)
45 45
     except ObjectDoesNotExist:
46  
-        raise validators.ValidationError, "Please enter a valid %s." % f.verbose_name
  46
+        raise validators.ValidationError, _("Please enter a valid %s.") % f.verbose_name
47 47
 
48 48
 def manipulator_validator_unique(f, opts, self, field_data, all_data):
49 49
     "Validates that the value is unique for this field."
@@ -57,7 +57,7 @@ def manipulator_validator_unique(f, opts, self, field_data, all_data):
57 57
         return
58 58
     if hasattr(self, 'original_object') and getattr(self.original_object, opts.pk.attname) == getattr(old_obj, opts.pk.attname):
59 59
         return
60  
-    raise validators.ValidationError, "%s with this %s already exists." % (capfirst(opts.verbose_name), f.verbose_name)
  60
+    raise validators.ValidationError, _("%(optname)s with this %(fieldname)s already exists.") % {'optname': capfirst(opts.verbose_name), 'fieldname': f.verbose_name}
61 61
 
62 62
 
63 63
 # A guide to Field parameters:
@@ -264,7 +264,7 @@ def get_manipulator_fields(self, opts, manipulator, change, name_prefix='', rel=
264 264
                     core_field_names.extend(f.get_manipulator_field_names(name_prefix))
265 265
             # Now, if there are any, add the validator to this FormField.
266 266
             if core_field_names:
267  
-                params['validator_list'].append(validators.RequiredIfOtherFieldsGiven(core_field_names, "This field is required."))
  267
+                params['validator_list'].append(validators.RequiredIfOtherFieldsGiven(core_field_names, gettext_lazy("This field is required.")))
268 268
 
269 269
         # BooleanFields (CheckboxFields) are a special case. They don't take
270 270
         # is_required or validator_list.
@@ -418,7 +418,7 @@ def __init__(self, other_field_names, other_file_field_name):
418 418
                         self.always_test = True
419 419
                     def __call__(self, field_data, all_data):
420 420
                         if not all_data.get(self.other_file_field_name, False):
421  
-                            c = validators.RequiredIfOtherFieldsGiven(self.other_field_names, "This field is required.")
  421
+                            c = validators.RequiredIfOtherFieldsGiven(self.other_field_names, gettext_lazy("This field is required."))
422 422
                             c(field_data, all_data)
423 423
                 # First, get the core fields, if any.
424 424
                 core_field_names = []
@@ -429,7 +429,7 @@ def __call__(self, field_data, all_data):
429 429
                 if core_field_names:
430 430
                     field_list[0].validator_list.append(RequiredFileField(core_field_names, field_list[1].field_name))
431 431
             else:
432  
-                v = validators.RequiredIfOtherFieldNotGiven(field_list[1].field_name, "This field is required.")
  432
+                v = validators.RequiredIfOtherFieldNotGiven(field_list[1].field_name, gettext_lazy("This field is required."))
433 433
                 v.always_test = True
434 434
                 field_list[0].validator_list.append(v)
435 435
                 field_list[0].is_required = field_list[1].is_required = False
@@ -438,7 +438,7 @@ def __call__(self, field_data, all_data):
438 438
         def isWithinMediaRoot(field_data, all_data):
439 439
             f = os.path.abspath(os.path.join(settings.MEDIA_ROOT, field_data))
440 440
             if not f.startswith(os.path.normpath(settings.MEDIA_ROOT)):
441  
-                raise validators.ValidationError, "Enter a valid filename."
  441
+                raise validators.ValidationError, _("Enter a valid filename.")
442 442
         field_list[1].validator_list.append(isWithinMediaRoot)
443 443
         return field_list
444 444
 
@@ -682,10 +682,11 @@ def isValidIDList(self, field_data, all_data):
682 682
         objects = mod.get_in_bulk(pks)
683 683
         if len(objects) != len(pks):
684 684
             badkeys = [k for k in pks if k not in objects]
685  
-            raise validators.ValidationError, "Please enter valid %s IDs. The value%s %r %s invalid." % \
686  
-                (self.verbose_name, len(badkeys) > 1 and 's' or '',
687  
-                len(badkeys) == 1 and badkeys[0] or tuple(badkeys),
688  
-                len(badkeys) == 1 and "is" or "are")
  685
+            raise validators.ValidationError, ngettext("Please enter valid %(self)s IDs. The value %(value)r is invalid.",
  686
+                    "Please enter valid %(self)s IDs. The values %(value)r are invalid.", len(badkeys)) % {
  687
+                'self': self.verbose_name,
  688
+                'value': len(badkeys) == 1 and badkeys[0] or tuple(badkeys),
  689
+            }
689 690
 
690 691
 class OneToOneField(IntegerField):
691 692
     def __init__(self, to, to_field=None, **kwargs):

0 notes on commit 807b406

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