{{{
class SearchForm(forms.Form):
search = forms.CharField(required=False)
}}}
and a view that uses the form in a GET:
{{{
def get_names(request):
if request.method == 'GET':
form = SearchForm(request.GET)
if form.is_valid():
query_result = ...
context = {'results': query_result, 'form': form}
else:
# handle failure
else:
form = SearchForm()
return render(request, 'name.html', {'form': form})
}}}
When the form is submitted trough GET, one gets an url like
`www.example.com/persons?search=...`
However, we typically want to i18n the parameters of the URL. I don't find
an easy way to do that. The way I'm doing now is
{{{
def add_prefix(self, field_name):
# HACK: ensures 'search' appears in translations
if field_name == 'search':
return _('search')
return _(field_name) # assumes other fields exist in the
translations
}}}
The suggestion here is to add an interface on the `Form` for the user to
overwrite how the form field names are mapped to html (currently they are
mapped to `field_name`). The implementation could be something on the
lines of:
1. maps `field_name` to its translation when the form is converted to
HTML.
2. maps translation back to `field_name` when the form receives data.
The flow could be: `SearchForm()` expects `{'busca': ...}`, and
`cleaned_data` returns `{'search': ...}`.
By default this mapping is the identity (1. field_name -> field_name; 2.
field_name -> field_name), that recovers the existing situation and is
thus backward compatible.
--
Ticket URL: <https://code.djangoproject.com/ticket/23927>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
Comment:
Is localizing form parameter names commonly done? It seems like it would
add a lot of complexity to JavaScript and CSS (e.g. it would hinder using
any name selectors). Do you know of any other web frameworks that support
this? I'd be curious if you could raise the issue on the
DevelopersMailingList to see what others think about it.
--
Ticket URL: <https://code.djangoproject.com/ticket/23927#comment:1>
Comment (by timgraham):
[https://groups.google.com/d/topic/django-
developers/r4PLC2apqwc/discussion django-developers thread]
--
Ticket URL: <https://code.djangoproject.com/ticket/23927#comment:2>
* status: new => closed
* resolution: => wontfix
Comment:
Closing according to the django-developers thread.
--
Ticket URL: <https://code.djangoproject.com/ticket/23927#comment:3>