For the internationalization of my django project, I'm using django's i18n, and I love it.
For setting the language in the template, instead of using forms like in this example :
<form action="{{site_url}}i18n/setlang/" method="post">
<input name="next" type="hidden" value="" />
<select name="language">
{% for language in languages %}
<option value="{{language.0}}">{{language.1}}</option>
{% endfor %}
</select>
<input type="submit" value="Ok" />
</form>
I would like to use simple plain text links; something like this:
{% for language in languages %}
{% ifnotequal language.0 lang %}
<a href="{{site_url}}i18n/setlang/" >{{language.1}}</a>{% else %}{{language.1}}
{% endifnotequal %}
...
{% endfor %}
For letting the previous template snippet do his work, I've created the following jQuery function:
var languageLink = $('#language-choser > a');
languageLink.click(function(e){
var languageURL = languageLink.attr('href');
var languageNow = languageLink.text();
var lang = (languageNow=='English') ? 'en' : 'es';
$.post(languageURL, {next: "", language:lang});
});
(I have to admit that I just began using jQuery)
This function works almost always with Firefox (but sometimes it simply doesn't nothing) and it never works with Chrome.
Someone can tell me what's wrong? I've been playing around with it for a long time, without finding a way out.
EDIT: Without any changes, everything is now working great. I can't understand why, and, obviously, I can't trust some code with such an irrational behavior...