向我的网站添加新语言后。我正在尝试更改网站语言,但无法正常工作。
from django.conf import locale
LANGUAGES = (
('en', _('English')),
('fr', _('French')),
('zz', _('Zulu Pic')),
)
EXTRA_LANG_INFO = {
'ht': {
'bidi': False, # right-to-left
'code': 'zz',
'name': 'Zulu Pic',
'name_local': u'Zulu Pic', #unicode codepoints here
},
}
locale.LANG_INFO = dict(locale.LANG_INFO,**EXTRA_LANG_INFO)
LANGUAGE_CODE = 'en'
我在根项目中设置了网址:
path('i18n/setlange', include('django.conf.urls.i18n')),
在我的HTML中:
<form action="{% url 'set_language' %}" method="post" class="">
<input name="next" type="hidden" value="{{ request.path }}">
{% csrf_token %}
<select name="language" class="form-control form-control-sm">
{% get_current_language as LANGUAGE_CODE %}
{% get_available_languages as LANGUAGES %}
{% get_language_info_list for LANGUAGES as languages %}
{% for language in languages %}
<option value="{{ language.code }}"{% if language.code == LANGUAGE_CODE %} selected="selected"{% endif %}>
{{ language.name_local|title }} ({{ language.code|upper }})
</option>
{% endfor %}
</select>
</form>
使用js提交表单
$("select[name=language]").change(function(){
$(this).closest("form").submit();
});
每次我选择zz作为语言时,都不会选择它。该网站显示默认值:“ EN”。
'FR'正常工作。