django 翻译模板中的变量内容 [英] django translate variable content in template

查看:19
本文介绍了django 翻译模板中的变量内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 {% trans %} 模板标签.Django 文档说:

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

{% trans %} 模板标签转换常量字符串(用单引号或双引号括起来)或变量内容:

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

{% trans "这是标题."%}{% trans myvar %}

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

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

我发现无法执行 {% trans myvar %} 因为 myvar 在运行 makemessages 命令后根本没有显示在 django.po 文件中.

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?

推荐答案

您可以使用 blocktrans 本例中的模板标签:

You can use the blocktrans template tag in this case:

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

这篇关于django 翻译模板中的变量内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆