Hello,
While trying to develop my first real Django project, I have come across an
*apparent* need to i18n'ize any arbitrary, unknown format string, with an
accompanying dictionary that contains the substitutes to insert into the
translated format string. For instance, I have a template that is displayed
when a certain SomeError is raised:
except SomeError as error:
render_to_response('myapp/some_error.html',
{ 'the_error': error },
context_instance=RequestContext(request))
I expect the SomeError object to contain information to be displayed to the
user. Specifically, SomeError will have a format_string attribute and a
substitute_dict attribute. The content of format_string is chosen at
runtime, but it is assumed that translations exist. For instance,
format_string could be:
"{{user}}, you cannot upload this video because you are out of quota.
You only have {{capacity}} out of {{quota}} left in your account."
or it could be:
"{{user}}, you cannot upload this video because it is in a format that
we don't accept ({{video_format}})."
Now assume that French, Spanish, Chinese, etc. translations exist for the
two example strings above.
And substitute_dict would contain the correct substitute strings. For
instance:
{
'user': 'Alice',
'capacity': '50 MB',
'quota': '20 GB',
}
or
{
'user': 'Alice',
'video_format': '3ivx',
}
As you can imagine, even Django's built-in {% blocktrans %} tag doesn't
seem to help here, for two reasons (as far as I understand):
1. it requires the substitutes to be explicitly declared and bound to
variables right in the template file;
2. it requires the i18n string to be spelled out between {% blocktrans %}
and {% endblocktrans %}; it cannot work with an i18n string that is
itself inside a variable.
Which means that I apparently need a new template tag, maybe something
called {% blockdicttrans format_string substitute_dict %}.
Is this madness? Have I overlooked some Django or Pythonic way? Or is it
actually a justifiable use case?
Cheers,
Kal
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/django-users/-/CcBuTPAHnd8J.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.