diff options
| author | Claude Paroz <claude@2xlibre.net> | 2013-07-13 11:43:14 +0200 |
|---|---|---|
| committer | Claude Paroz <claude@2xlibre.net> | 2013-07-13 16:20:09 +0200 |
| commit | db33b25e8617185acbadb4ff04eaa4c37ae67dd6 (patch) | |
| tree | 1451e3cf6197ada7a09f58f9a64183ba638ded41 /django/forms | |
| parent | 7f210563ab90d4d3957e7e1efc5b102777357e8b (diff) | |
[1.6.x] Fixed #20582 -- Allowed default Form.label_suffix to be translated
Thanks Tim Graham for the review.
Backport of 7557207983 from master.
Diffstat (limited to 'django/forms')
| -rw-r--r-- | django/forms/forms.py | 9 | ||||
| -rw-r--r-- | django/forms/models.py | 2 |
2 files changed, 7 insertions, 4 deletions
diff --git a/django/forms/forms.py b/django/forms/forms.py index b25eeb30a4..6c062bed0f 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 821f64199b..c18680247d 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: |
