From 755720798393e78fc3094cc3f790852737cb6813 Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Sat, 13 Jul 2013 11:43:14 +0200 Subject: [PATCH] Fixed #20582 -- Allowed default Form.label_suffix to be translated Thanks Tim Graham for the review. --- django/conf/locale/en/LC_MESSAGES/django.po | 15 +++++++++++++-- django/forms/forms.py | 9 ++++++--- django/forms/models.py | 2 +- docs/ref/forms/api.txt | 15 +++++++++++---- 4 files changed, 31 insertions(+), 10 deletions(-) diff --git a/django/conf/locale/en/LC_MESSAGES/django.po b/django/conf/locale/en/LC_MESSAGES/django.po index 371f0af2ab..f8069f07d2 100644 --- a/django/conf/locale/en/LC_MESSAGES/django.po +++ b/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 \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." diff --git a/django/forms/forms.py b/django/forms/forms.py index 6d59271d17..e144eb60f8 100644 --- a/django/forms/forms.py +++ b/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 @@ class BaseForm(object): 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 @@ class BoundField(object): """ 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 diff --git a/django/forms/models.py b/django/forms/models.py index a0c3009d38..1d3bec1635 100644 --- a/django/forms/models.py +++ b/django/forms/models.py @@ -292,7 +292,7 @@ class ModelFormMetaclass(type): 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: diff --git a/docs/ref/forms/api.txt b/docs/ref/forms/api.txt index 5d54e01c3d..7c1601d3ea 100644 --- a/docs/ref/forms/api.txt +++ b/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::
  • 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 ~~~~~~~~~~~~~~~~~~~~~~~