Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #20582 -- Allowed default Form.label_suffix to be translated

Thanks Tim Graham for the review.
  • Loading branch information...
commit 755720798393e78fc3094cc3f790852737cb6813 1 parent 73f86f4
Claude Paroz authored
15  django/conf/locale/en/LC_MESSAGES/django.po
@@ -4,7 +4,7 @@ msgid ""
4 4
 msgstr ""
5 5
 "Project-Id-Version: Django\n"
6 6
 "Report-Msgid-Bugs-To: \n"
7  
-"POT-Creation-Date: 2013-05-25 14:27+0200\n"
  7
+"POT-Creation-Date: 2013-06-11 18:44+0200\n"
8 8
 "PO-Revision-Date: 2010-05-13 15:35+0200\n"
9 9
 "Last-Translator: Django team\n"
10 10
 "Language-Team: English <en@li.org>\n"
@@ -699,11 +699,22 @@ msgstr ""
699 699
 msgid "Enter a list of values."
700 700
 msgstr ""
701 701
 
702  
-#: forms/forms.py:158
  702
+#. Translators: This is the default suffix added to form field labels
  703
+#: forms/forms.py:90
  704
+msgid ":"
  705
+msgstr ""
  706
+
  707
+#: forms/forms.py:159
703 708
 #, python-format
704 709
 msgid "(Hidden field %(name)s) %(error)s"
705 710
 msgstr ""
706 711
 
  712
+#. Translators: If found as last label character, these punctuation
  713
+#. characters will prevent the default label_suffix to be appended to the label
  714
+#: forms/forms.py:525
  715
+msgid ":?.!"
  716
+msgstr ""
  717
+
707 718
 #: forms/formsets.py:310
708 719
 #, python-format
709 720
 msgid "Please submit %d or fewer forms."
9  django/forms/forms.py
@@ -77,7 +77,7 @@ class BaseForm(object):
77 77
     # information. Any improvements to the form API should be made to *this*
78 78
     # class, not to the Form class.
79 79
     def __init__(self, data=None, files=None, auto_id='id_%s', prefix=None,
80  
-                 initial=None, error_class=ErrorList, label_suffix=':',
  80
+                 initial=None, error_class=ErrorList, label_suffix=None,
81 81
                  empty_permitted=False):
82 82
         self.is_bound = data is not None or files is not None
83 83
         self.data = data or {}
@@ -86,7 +86,8 @@ def __init__(self, data=None, files=None, auto_id='id_%s', prefix=None,
86 86
         self.prefix = prefix
87 87
         self.initial = initial or {}
88 88
         self.error_class = error_class
89  
-        self.label_suffix = label_suffix
  89
+        # Translators: This is the default suffix added to form field labels
  90
+        self.label_suffix = label_suffix if label_suffix is not None else _(':')
90 91
         self.empty_permitted = empty_permitted
91 92
         self._errors = None # Stores the errors after clean() has been called.
92 93
         self._changed_data = None
@@ -518,7 +519,9 @@ def label_tag(self, contents=None, attrs=None):
518 519
         """
519 520
         contents = contents or self.label
520 521
         # Only add the suffix if the label does not end in punctuation.
521  
-        if self.form.label_suffix and contents and contents[-1] not in ':?.!':
  522
+        # Translators: If found as last label character, these punctuation
  523
+        # characters will prevent the default label_suffix to be appended to the label
  524
+        if self.form.label_suffix and contents and contents[-1] not in _(':?.!'):
522 525
             contents = format_html('{0}{1}', contents, self.form.label_suffix)
523 526
         widget = self.field.widget
524 527
         id_ = widget.attrs.get('id') or self.auto_id
2  django/forms/models.py
@@ -292,7 +292,7 @@ def __new__(cls, name, bases, attrs):
292 292
 
293 293
 class BaseModelForm(BaseForm):
294 294
     def __init__(self, data=None, files=None, auto_id='id_%s', prefix=None,
295  
-                 initial=None, error_class=ErrorList, label_suffix=':',
  295
+                 initial=None, error_class=ErrorList, label_suffix=None,
296 296
                  empty_permitted=False, instance=None):
297 297
         opts = self._meta
298 298
         if opts.model is None:
15  docs/ref/forms/api.txt
@@ -500,9 +500,15 @@ By default, ``auto_id`` is set to the string ``'id_%s'``.
500 500
 
501 501
 .. attribute:: Form.label_suffix
502 502
 
503  
-Normally, a colon (``:``) will be appended after any label name when a form is
504  
-rendered. It's possible to change the colon to another character, or omit it
505  
-entirely, using the ``label_suffix`` parameter::
  503
+A translatable string (defaults to a colon (``:``) in English) that will be
  504
+appended after any label name when a form is rendered.
  505
+
  506
+.. versionchanged:: 1.6
  507
+
  508
+    The default ``label_suffix`` is translatable.
  509
+
  510
+It's possible to customize that character, or omit it entirely, using the
  511
+ ``label_suffix`` parameter::
506 512
 
507 513
     >>> f = ContactForm(auto_id='id_for_%s', label_suffix='')
508 514
     >>> print(f.as_ul())
@@ -518,7 +524,8 @@ entirely, using the ``label_suffix`` parameter::
518 524
     <li><label for="id_for_cc_myself">Cc myself -></label> <input type="checkbox" name="cc_myself" id="id_for_cc_myself" /></li>
519 525
 
520 526
 Note that the label suffix is added only if the last character of the
521  
-label isn't a punctuation character (``.``, ``!``, ``?`` or ``:``)
  527
+label isn't a punctuation character (in English, those are ``.``, ``!``, ``?``
  528
+or ``:``).
522 529
 
523 530
 Notes on field ordering
524 531
 ~~~~~~~~~~~~~~~~~~~~~~~

0 notes on commit 7557207

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