After taking a look at the django translation mecanism, I did not
find a feature (I think) that is mandatory for what I'm trying to do :
I'd like to have a translatable message that displays (in a page)
something like :
"This has been done by the user xxx" ... and of course, the "xxx" is
the name of the user, it's dynamic, AND I'd like it to be a link to "/
users/xxx" ...
Is there a way to do that with django without putting any html code
(a href) in the translation file ?
Best,
AD
If you only want the "xxx" bit to be a link, substitute in the HTML at
that time. So the thing you substitute will be "<a href="...">xxx</a>"
instead of just the normal "xxx". If you want the whole thing to be a
link, wrap it all in a link in the template.
There isn't really any magic way to do this and no standard function is
going to help you. Either you HTML in the string that is translated (not
ideal, but not always avoidable) or you include it at substitution time.
Please post follow ups to django-users, since this is a "how do I..."
thread, rather than something needed internal development (I realise
it's borderline initially, but there's no way to get what you need
directly here.
Regards,
Malcolm
Thanks a lot for the response.
Actually, I "dare" to reply here because I think what follows might
be a hint for the developers if they agree that the feature I'm
talking about is worth a look.
Such a translation feature is for instance available in Zope/Plone
translation mecanism : here is an example of the template (in zpt, a
little bit simplified because my goal is only to illustrate my point)
<p i18n:translate="description_no_account">
go to the ...
<span i18n:name="registration_form">
<a href="test" i18n:translate="the_desc_key">
registration form</a></span>.
</p>
this would produce : "</p>go to the ... <a href="test">registration
form</p>"
the key "description_no_account" is the i18n key for the words "go
to the ...{registration_form} "
the key "the_desc_key" is the i18n key for the words "registration
form"
my 0.002$ :-)
actually, I'm not used to django to start coding and propose a patch
right away but this might come in the future ... just wondering how
this could be done in django (maybe a few developer hint on this could
get me started ;-) ) ...
Regards,
AD
I cannot visualise what the equivalent Django template language would
look like. Perhaps you could rewrite this in an analogous syntax to what
it would look like in Django? The difficulty I am having is that
translations are marked up with a specific template tag. So you cannot
just merge template directives in with existing HTML. Any HTML tags will
be fully outside the translation block or fully inside it.
I'm not convinced this is a missing feature yet. Writing
<p>{% trans "go to the ..." %}<span><a href="test">{% trans
"registration form" %}</a></span>
is the current Django way to rewrite your example. Not sure how that can
be made simpler without changing the philosophy behind the template
language. However, if you suggest the sort of syntax you are thinking
of, it will make commenting easier.
Your first example would be something like
<p>{% trans "This has been done by user" %}
<a href="{{ user.get_absolute_url }}">{{ user }}</a>
Again, hard to imagine how it could be made simpler given the constraint
that translation markup is a normal template tag.
Regards,
Malcolm
The thing is that you want to render a sentence like "go to the page
registration form" with a link on "registration form" ... but you dont
want the translated sentence to be splited in 2 (because another
language might not be able to support that). thus you dont that :
<p>{% trans "go to the page" %}<span><a href="test">{% trans
"registration form" %}</a></span>
if in another language the same sentence is written "backwards" with
the words on which the link should be (registration form) in first
position, then it's not working.
Writting pseudo-django code I would say this could be written (I'm not
suggesting anything like that, but I hope this could help me make my
point ) :
[ I use a new tag "with" that is almost the same thing as when you
write {% blocktrans with value|filter as myvar %} : it defines a value
that will be used to replace a gap inside a translated string ]
{% blocktrans%}
{% with page_name %}
<a href="/test">
{% blocktrans%}registration form{% endblocktrans %}
</a>
{% endwith %}
go to the page {{ page_name }}.
{% endblocktrans %}
This way you would have the possiblity to replace something with html
(links) inside the value of a translated string.
Does that make more sense ?
Regards,
AD
I would be happy to know you're impressions about the above
explanation ... if I made my point clear or not, or if you have any
objection why this would not be a useful feature ...
Regards,
--
AD
I can see the advantage of the Zope/Plone template solution, which
tackles exactly this problem. My colleague Tobias has solved this in
the following way, which might not be very readable and not ideal not
for maintenance, but it does work very well!!!
The plural is an additional thing, which makes it even more
complicated to read :-)
But it works ...
{% blocktrans count tagged_users|length as counter
with tagged_users|length as tagged_users_length
and tag_type|stringformat:"<span class='%s'>" as span_open
and "</span>" as span_close %}
{{ tagged_users_length }} users also has this
{{ span_open }}{{ tag_type_translated }}{{ span_close }}
{% plural %}
{{ tagged_users_length }} users also have this {{ span_open }}
{{ tag_type_translated }}{{ span_close }}
{% endblocktrans %}
have a try alain
good luck
wolfram
--
cu
Wolfram
--
cu
Wolfram
I understood your point. I haven't had time to think about it fully yet.
My gut feeling is that I don't like your proposed syntax -- there's
probably something a closer to what we already have that can be used
(perhaps a variation on the "noop" argument to {% trans %}). The idea is
not to force people to have to reach for teh instruction manual
everytime they need to use it.
It will be a little while before I can get back to this
Regards,
Malcolm
That's effectively a bug. Should be fixed at some point. It's been
reported in Trac. Kind of takes the fun out of the "block" tag if you
can't use it for blocks of text; very inconsistent.
Regards,
Malcolm
--
cu
Wolfram
wolfram
On 6/14/07, Wolfram Kriesing <wolfram....@gmail.com> wrote:
--
cu
Wolfram