1. settings.py --> MIDDLEWARE_CLASSES add
"django.middleware.locale.LocaleMiddleware"
2. urls.py add
(r'^i18n/', include('django.conf.urls.i18n')),
3. admin interface
select menu
<form action="/i18n/setlang/" method="post">{% csrf_token %}
<input name="next" type="hidden" value="/" />
<select name="language">
{% for lang in LANGUAGES %}
<option value="{{ lang.0 }}">{{ lang.1 }}</option>
{% endfor %}
</select>
<input type="submit" value="{% trans "submit" %}" />
</form>
<input name="next" type="hidden" value="/" />
<select name="language">
{% for lang in LANGUAGES %}
<option value="{{ lang.0 }}">{{ lang.1 }}</option>
{% endfor %}
</select>
<input type="submit" value="{% trans "submit" %}" />
</form>
link
<form name="setLangEnglish" action="/i18n/setlang/" method="POST">{% csrf_token %}
<input name="next" type="hidden" value="/" />
<input type="hidden" name="language" value="en" />
<a href="#" onclick="document.setLangEnglish.submit();return false;">English</a>
</form>
<form name="setLangZh_tw" action="/i18n/setlang/" method="POST">{% csrf_token %}
<input name="next" type="hidden" value="/" />
<input type="hidden" name="language" value="zh-tw" />
<a href="#" onclick="document.setLangZh_tw.submit();return false;">{% trans "Traditional Chinese" %}</a>
</form>
<input name="next" type="hidden" value="/" />
<input type="hidden" name="language" value="en" />
<a href="#" onclick="document.setLangEnglish.submit();return false;">English</a>
</form>
<form name="setLangZh_tw" action="/i18n/setlang/" method="POST">{% csrf_token %}
<input name="next" type="hidden" value="/" />
<input type="hidden" name="language" value="zh-tw" />
<a href="#" onclick="document.setLangZh_tw.submit();return false;">{% trans "Traditional Chinese" %}</a>
</form>
*.py
from django.utils.translation import ugettext_lazy as _
_("term")
_(u"要翻譯的字串")
_("term")
_(u"要翻譯的字串")
template *.html
{% load i18n future grp_tags %}
{% trans "Traditional Chinese" %}
{% trans "Documentation" %}
{% trans "Traditional Chinese" %}
{% trans "Documentation" %}
0 留言