我可以切换到ru
和en
,但当我尝试切换到hy
时,没有任何反应。
settings.py
...
LANGUAGE_CODE = 'en'
LANGUAGES = [
('en',_('English')),
('ru', _(u'Russian')),
('hy', _(u'Armenian')),
]
sidebar.html
...
<div id="sidebar-item-news">
<form action="/i18n/setlang/" method="post" id="language-select">
<input name="next" type="hidden" value="/" />
{% csrf_token %}
<select name="language">
{% for lang in LANGUAGES %}
<option value="{{ lang.0 }}">{{ lang.1 }}</option>
{% endfor %}
</select>
<input type="submit" value="Go" />
</form>
</div>
urls.py
# Internationalization
(r'^i18n/', include('django.conf.urls.i18n')),
经过一些调试后,我发现request.session ['django_language']仅更改为ru
和en
:
Current language is ru
[19/May/2012 22:51:55] "GET / HTTP/1.1" 200 13357
[19/May/2012 22:51:56] "POST /i18n/setlang/ HTTP/1.1" 302 0
Current language is ru
[19/May/2012 22:51:56] "GET / HTTP/1.1" 200 13357
我已在/locale/hy
和/locale/ru
如果我放入主视图translation.activate('hy')
它完美无缺,但如果我尝试使用我的api
def api(request, type):
if request.method == 'POST':
if type == 'daytime':
request.session['daytime'] = request.POST['daytime']
return HttpResponse(request.session['daytime'])
if type == 'language':
request.session['custom_language'] = True
request.session['django_language'] = request.POST['language']
translation.activate(request.session['django_language'] )
return HttpResponse(request.session['django_language'])
raise Http404
else:
raise Http404
它以i18n/setlang
形式失败。
如何解决这个问题?
UPD Django似乎不支持亚美尼亚语。 (/ django / conf / locale /中没有'hy') 我应该如何使用这种语言?