tuf*_*fla 5 django translation django-templates internationalization
Django 1.4 doc说您可以将翻译后的字符串转换为"vars"以在不同的地方使用,或者使用以下语法在模板标签或过滤器中用作参数:
{% trans "String" as my_translated_string %}
<h1>{{ my_translated_string }}</h1>
Run Code Online (Sandbox Code Playgroud)
https://docs.djangoproject.com/en/1.4/topics/i18n/translation/#trans-template-tag
我这样做,但定义的var永远不会呈现内容.在我的模板代码下面:
{% extends "default_layout.html" %}
{% load i18n %}
{% trans "My page title" as title %}
{% block meta_title %}{{ title }}{% endblock %}
{% block content %}
<h1>{{ title }}</h1>
{% endblock %}
Run Code Online (Sandbox Code Playgroud)
当然,在两种情况下,"标题"都呈现为空.
我错过了什么吗?
谢谢.
如上所述,okm您需要在要使用它的块中定义变量,并且该变量的范围也在块内:
{% extends "default_layout.html" %}
{% load i18n %}
{% block meta_title %}
{% trans "My page title" as title %}
{{ title }}
{% endblock %}
{% block content %}
{% trans "My page title" as title %}
<h1>{{ title }}</h1>
{% endblock %}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2243 次 |
| 最近记录: |