标签:
>django-admin startproject I18nDjango
>manage.py startapp i18n
from django.utils.translation import ugettext
def index(request):
return HttpResponse(ugettext(‘hello world!‘))
{% load i18n %}
<h1>translation</h1>
<p>{% trans "This is the p element." %}</p>
django-admin.py makemessages -l de
LANGUAGE_CODE = ‘en-us‘
TIME_ZONE = ‘UTC‘
USE_I18N = True
USE_L10N = True
LOCALE_PATHS = (‘locale/‘,
)
django-admin.py makemessages -a
django-admin.py compilemessages
下面这个中间件能让Django网站根据配置或Accept-Language返回资源文件中对应语言的字符串
MIDDLEWARE_CLASSES = (
... ...
‘django.middleware.locale.LocaleMiddleware‘,
)
实验代码请看
* https://github.com/ybdesire/WebLearn/tree/master/14_Django/I18nDjango
更多Djang的I18n细节请看 这里
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:
原文地址:http://blog.csdn.net/ybdesire/article/details/46806739