django-crispy-forms / django-crispy-forms/django-crispy-forms
Translation does not work for button used within common layout
- Dominant language
- Python
- Stars
- 5.2k
- Forks
- 731
- PR merge metrics
- No merged PRs in 30d
Description
* Package version: 1.8.1
* Django version: 3.0.1
* Python version: 3.7.6
* Template pack: (Optional)
### Description:
Translation does not work for button text when used within a common layout as described in the docs [here](https://django-crispy-forms.readthedocs.io/en/latest/layouts.html#composing-layouts). The translation does not update as it should when the language is changed.
### Steps to reproduce:
- Go to [this heroku app](https://django-crispy-forms-lazy-issue.herokuapp.com/en/).
- Switch the language using language selection links at the bottom.
- Language updates for the whole page except for the button text.
See the source code of it [here on GitHub](https://github.com/monim67/django-crispy-forms-lazy-issue/blob/f544a4c/btn_translation_issue/forms.py#L7-L11) using common layout for buttons.
### Why this happens:
This happens because when `BaseInput` class of crispy-forms renders it converts the lazy django translation object passed as `value` to string and stores it back to `value` overwriting it [here](https://github.com/django-crispy-forms/django-crispy-forms/blob/b55b86a/crispy_forms/layout.py#L197), hence the lazy translation object is lost upon the first render of the input element. If we don't overwrite the original `value` the issue is resolved.
Contributor guide
Assessment
This issue has not been assessed yet.