使用i118n查找键[LANGUAGES]的错误

时间:2012-10-24 11:05:52

标签: django internationalization

我很难让i118工作。当我调用我的HTML时,我得到:

Failed lookup for key [LANGUAGES] in u"[{'projects': [<Project: etwas>]}]"

这是我的工作流程:

#setting.py
LANGUAGE_CODE = 'de'

ugettext = lambda s: s

LANGUAGES = (
   ('de', ugettext('German')),
   ('en', ugettext('English')),
   ('pt', ugettext('Portuges')),
)

MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.locale.LocaleMiddleware',
    #...

TEMPLATE_CONTEXT_PROCESSORS = global_settings.TEMPLATE_CONTEXT_PROCESSORS + (
    'django.core.context_processors.i18n',
)


#base.html
{% load i18n %}
<html>
<body>
<form action="/i18n/setlang/" method="post"> 
{% csrf_token %}
<input name="next" type="hidden" value="next/page" /> 
<select name="language"> 
{% get_language_info_list for LANGUAGES as languages %}
{% for language in languages %}
    <option value="{{ language.code }}">{{ language.name_local }}  ({{ language.code }})</option>
{% endfor %}

#projects.html
{% extends 'base.html' %}
{% load i18n %} 
{% block content %}
{% for p in projects %}
    <h1>{{ p.title_en }}</h1>
    <p>{{ p.body_de }} </p>
    <p>{{ p.body_pt }} </p>
    <hr>    
{% endfor %}
{% endblock %}

我错过了什么?我无法在线找到有关错误消息的任何有用信息。

2 个答案:

答案 0 :(得分:1)

看起来您没有使用RequestContext

答案 1 :(得分:1)

似乎没有正确调用'django.core.context_processors.i18n'

这可能是因为您的视图使用的django.shorcuts.render_to_response没有context_instance=template.RequestContext(request)

解决方案是切换到django.shortcuts.render