Reputation: 658
I'm trying to internationalize my webpages by using the {% trans "string" %}
method in django.
However I get an error when I try to use quotes in the string. I've already tried to escape them with a backslash with no luck.
How can I escape something like this:
{% trans "foo's is like "foo"." %}
As I said, this doesn't work:
{% trans "foo\'s is like \"foo\"." %}
Any idea?
Thanks
Upvotes: 6
Views: 4511
Reputation: 151203
Note that the {% translate %}
and the {% blocktranslate %}
template tags are generally meant to be used with HTML. So you could simply escape them as you would in HTML:
{% blocktranslate %}foo's is like "foo"{% endblocktranslate %}
<br>
{% trans "foo's is like "foo"" %}
Assuming that the language is set to the default language (English), this would send this HTML to the browser:
foo's is like "foo"
<br>
foo's is like "foo"
The user would see on the screen this text:
foo's is like "foo"
foo's is like "foo"
By the way, the template tag {% translate %}
is just an alias for {% trans %}
, and {% blocktranslate %}
is just an alias for {% blocktrans %}
.
Upvotes: 0
Reputation: 799190
Use blocktrans
instead.
{% blocktranslate %}Just an example block to translate with {{value}} and text.{% endblocktranslate %}
Upvotes: 13