Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[1.6.x] Fixed #20582 -- Allowed default Form.label_suffix to be trans…

…lated

Thanks Tim Graham for the review.
Backport of 7557207 from master.
  • Loading branch information...
commit db33b25e8617185acbadb4ff04eaa4c37ae67dd6 1 parent 7f21056
@claudep claudep authored
View
15 django/conf/locale/en/LC_MESSAGES/django.po
@@ -4,7 +4,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Django\n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2013-05-25 14:27+0200\n"
+"POT-Creation-Date: 2013-06-11 18:44+0200\n"
"PO-Revision-Date: 2010-05-13 15:35+0200\n"
"Last-Translator: Django team\n"
"Language-Team: English <en@li.org>\n"
@@ -699,11 +699,22 @@ msgstr ""
msgid "Enter a list of values."
msgstr ""
-#: forms/forms.py:158
+#. Translators: This is the default suffix added to form field labels
+#: forms/forms.py:90
+msgid ":"
+msgstr ""
+
+#: forms/forms.py:159
#, python-format
msgid "(Hidden field %(name)s) %(error)s"
msgstr ""
+#. Translators: If found as last label character, these punctuation
+#. characters will prevent the default label_suffix to be appended to the label
+#: forms/forms.py:525
+msgid ":?.!"
+msgstr ""
+
#: forms/formsets.py:310
#, python-format
msgid "Please submit %d or fewer forms."
View
9 django/forms/forms.py
@@ -77,7 +77,7 @@ class BaseForm(object):
# information. Any improvements to the form API should be made to *this*
# class, not to the Form class.
def __init__(self, data=None, files=None, auto_id='id_%s', prefix=None,
- initial=None, error_class=ErrorList, label_suffix=':',
+ initial=None, error_class=ErrorList, label_suffix=None,
empty_permitted=False):
self.is_bound = data is not None or files is not None
self.data = data or {}
@@ -86,7 +86,8 @@ def __init__(self, data=None, files=None, auto_id='id_%s', prefix=None,
self.prefix = prefix
self.initial = initial or {}
self.error_class = error_class
- self.label_suffix = label_suffix
+ # Translators: This is the default suffix added to form field labels
+ self.label_suffix = label_suffix if label_suffix is not None else _(':')
self.empty_permitted = empty_permitted
self._errors = None # Stores the errors after clean() has been called.
self._changed_data = None
@@ -518,7 +519,9 @@ def label_tag(self, contents=None, attrs=None):
"""
contents = contents or self.label
# Only add the suffix if the label does not end in punctuation.
- if self.form.label_suffix and contents and contents[-1] not in ':?.!':
+ # Translators: If found as last label character, these punctuation
+ # characters will prevent the default label_suffix to be appended to the label
+ if self.form.label_suffix and contents and contents[-1] not in _(':?.!'):
contents = format_html('{0}{1}', contents, self.form.label_suffix)
widget = self.field.widget
id_ = widget.attrs.get('id') or self.auto_id
View
2  django/forms/models.py
@@ -292,7 +292,7 @@ def __new__(cls, name, bases, attrs):
class BaseModelForm(BaseForm):
def __init__(self, data=None, files=None, auto_id='id_%s', prefix=None,
- initial=None, error_class=ErrorList, label_suffix=':',
+ initial=None, error_class=ErrorList, label_suffix=None,
empty_permitted=False, instance=None):
opts = self._meta
if opts.model is None:
View
15 docs/ref/forms/api.txt
@@ -500,9 +500,15 @@ By default, ``auto_id`` is set to the string ``'id_%s'``.
.. attribute:: Form.label_suffix
-Normally, a colon (``:``) will be appended after any label name when a form is
-rendered. It's possible to change the colon to another character, or omit it
-entirely, using the ``label_suffix`` parameter::
+A translatable string (defaults to a colon (``:``) in English) that will be
+appended after any label name when a form is rendered.
+
+.. versionchanged:: 1.6
+
+ The default ``label_suffix`` is translatable.
+
+It's possible to customize that character, or omit it entirely, using the
+ ``label_suffix`` parameter::
>>> f = ContactForm(auto_id='id_for_%s', label_suffix='')
>>> print(f.as_ul())
@@ -518,7 +524,8 @@ entirely, using the ``label_suffix`` parameter::
<li><label for="id_for_cc_myself">Cc myself -></label> <input type="checkbox" name="cc_myself" id="id_for_cc_myself" /></li>
Note that the label suffix is added only if the last character of the
-label isn't a punctuation character (``.``, ``!``, ``?`` or ``:``)
+label isn't a punctuation character (in English, those are ``.``, ``!``, ``?``
+or ``:``).
Notes on field ordering
~~~~~~~~~~~~~~~~~~~~~~~
Please sign in to comment.
Something went wrong with that request. Please try again.