Skip to content

Instantly share code, notes, and snippets.

@jerivas
Created May 13, 2014 20:33
Show Gist options
  • Save jerivas/8f9873c36cd8a895cd4a to your computer and use it in GitHub Desktop.
Save jerivas/8f9873c36cd8a895cd4a to your computer and use it in GitHub Desktop.
One-click Django language select
# settings.py
TEMPLATE_CONTEXT_PROCESSORS = (
'django.core.context_processors.i18n',
)
# urls.py (outside i18n_patterns)
(r'^i18n/', include('django.conf.urls.i18n')),
{% get_language_info_list for LANGUAGES as languages %}
{% if settings.USE_I18N and languages|length > 1 %}
<form action="{% url "set_language" %}" method="post" class="navbar-form navbar-right">
{% csrf_token %}
<div class="form-group">
<select name="language" class="form-control" onchange="this.form.submit()">
{% for language in languages %}
<option value="{{ language.code }}"
{% if language.code == LANGUAGE_CODE %}selected="selected"{% endif %}>
{{ language.name_local }}
</option>
{% endfor %}
</select>
</div>
</form>
{% endif %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment