Skip to content

Instantly share code, notes, and snippets.

@CapnKernel
Created July 7, 2016 10:15
Show Gist options
  • Save CapnKernel/bd06d876f0c522c9712c880c90b7c554 to your computer and use it in GitHub Desktop.
Save CapnKernel/bd06d876f0c522c9712c880c90b7c554 to your computer and use it in GitHub Desktop.
{% get_current_language as LANGUAGE_CODE %}
<div id="lang_section" class="float-right">
<form action="{% url 'set_language' %}" method="post" id="base-lang-form">
{% csrf_token %}
<select name="language" id="base-lang-selector">
{% for lang in LANGUAGES %}
<option value="{{ lang.0 }}"{% if lang.0 == LANGUAGE_CODE %} selected{% endif %}>{% trans lang.1 %}</option>
{% endfor %}
</select>
</form>
<script type="text/javascript">
$("#base-lang-selector").change(function() {
$("#base-lang-form").submit();
});
</script>
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'hv.views.home', name='home'),
# url(r'^hv/', include('hv.foo.urls')),
# Uncomment the admin/doc line below to enable admin documentation:
# url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
# ...
url(r'^i18n/setlang/$', 'django.views.i18n.set_language', name='set_language'),
url(r'^admin/', include(admin.site.urls)),
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment