Created
September 26, 2013 23:56
-
-
Save Natim/6722268 to your computer and use it in GitHub Desktop.
Django selecteur de langue
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
{% load static i18n i18nurl %} | |
{% get_available_languages as LANGUAGES %} | |
{% for language_code, language_name in LANGUAGES %} | |
{% language language_code %} | |
<li><a href="#{{ language_code }}" class="{% if language_code == LANGUAGE_CODE %} active{% endif %}" data-lang="{{ language_code }}" data-next="{% current_i18nurl language_code %}"><i class="sprite-flag-{{ language_code }}"></i>{{ language_name }}</a></li> | |
{% endlanguage %} | |
{% endfor %} | |
<script type="text/javascript"> | |
$(document).ready(function() { | |
$('a[data-lang]').click(function() { | |
var form = $('<form method="post">').attr('action', "{% url 'set_language' %}"); | |
var csrftoken = "{% csrf_token %}"; | |
var next = $('<input type="hidden"/>').attr({"name": "next", "value": $(this).attr('data-next')}); | |
var language = $('<input type="hidden"/>').attr({"name": "language", "value": $(this).attr('data-lang')}); | |
$(form).append(csrftoken); | |
$(form).append(next); | |
$(form).append(language); | |
$('body').append(form); | |
$(form).submit(); | |
}); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment