Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
619 views
in Technique[技术] by (71.8m points)

internationalization - django translate variable content in template

I'm using {% trans %} template tag. Django docs say:

The {% trans %} template tag translates either a constant string (enclosed in single or double quotes) or variable content:

{% trans "This is the title." %} {% trans myvar %}

https://docs.djangoproject.com/en/1.3/topics/i18n/internationalization/#trans-template-tag

I found it impossible to do {% trans myvar %} because myvar simply doesn't show up in django.po file after running makemessages command.

Am I using it wrong? Could some help me with this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can use the blocktrans template tag in this case:

{% blocktrans %} This is the title: {{ myvar }} {% endblocktrans %}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...