我正在建立一个新的小项目,在Django 1.4.3(英语和荷兰语)中尝试i18n。但我认为我错过了一步,因为它没有翻译字符串。
谁能告诉我需要做些什么才能获得翻译后的字符串?我该如何调试?
settings.py :
gettext = lambda s: s
LANGUAGES = (
('nl', gettext('Dutch')),
('en', gettext('English')),
)
LOCALE_PATH= (
'/var/www/test/locale',
)
# django.middleware.locale.LocaleMiddleware is also included @ MIDDLEWARE_CLASSES
urls.py 文件:
urlpatterns = i18n_patterns('',
#home
url(r'^$','bday.views.home',name="index"),
)
项目中的views.py :
from django.utils.translation import ugettext as _
def home(request):
text=_("Welcome!")
return HttpResponse("LANG[{}], TEXT[{}]".format( request.LANGUAGE_CODE, text ) )
的/ var / WWW /测试/区域/的 NL / LC_MESSAGES / django的。的 PO
#: bday/views.py:16
msgid "Welcome!"
msgstr "Welkon in Nederlands"
的/ var / WWW /测试/区域/的 EN / LC_MESSAGES / django的。的 PO
#: bday/views.py:16
msgid "Welcome!"
msgstr "Welcome in English"
邮件会被编译,我得到:
./manage.py compilemessages
processing file django.po in /var/www/test/locale/nl/LC_MESSAGES
processing file django.po in /var/www/test/locale/en/LC_MESSAGES
但是在我的应用中,我得到了:
$ curl "http://www.host.com:8000/nl/"
LANG[nl], TEXT[Welcome!]
$ curl "http://www.host.com:8000/en/"
LANG[en], TEXT[Welcome!]