-
-
Save teury/481c5383be2b3e0409b8c961ab79166e to your computer and use it in GitHub Desktop.
One-click Django language select
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# settings.py | |
TEMPLATE_CONTEXT_PROCESSORS = ( | |
'django.core.context_processors.i18n', | |
) | |
# urls.py (outside i18n_patterns) | |
(r'^i18n/', include('django.conf.urls.i18n')), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% 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