我可以切换到ru
and en
,但是当我尝试切换到 时hy
,什么也没有发生。
设置.py
...
LANGUAGE_CODE = 'en'
LANGUAGES = [
('en',_('English')),
('ru', _(u'Russian')),
('hy', _(u'Armenian')),
]
边栏.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>
网址.py
# Internationalization
(r'^i18n/', include('django.conf.urls.i18n')),
经过一些调试后,我发现 request.session['django_language'] 仅更改为ru
and 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”)我应该如何使用这种语言?