I have the following code that works perfectly.
It is code from one of my WordPress blog's plugin and all it does is create a drop-down list and then lets users navigate the site based on the language they choose.
The only think it is missing is that when a different language is chosen and the user goes to that page, in the drop-down it resets the language to the one that has the "selected" property turned on, which is "English".
I need the drop-down to display the item/language that was chosen to get them to that page. So, for example, if I chose "Deutsch" then when it gets to that page, it should say "Deutsch" in the drop-down menu.
Any ideas how to tweak this code to achieve that..??
<ul class="qtrans_language_chooser" id="mqtranslate-2-chooser"><li class="lang-de"><a href="http://localhost/tshirts/?lang=de" hreflang="de" title="Deutsch"><span>Deutsch</span></a></li><li class="lang-en active"><a href="http://localhost/tshirts/" hreflang="en" title="English"><span>English</span></a></li><li class="lang-fr"><a href="http://localhost/tshirts/?lang=fr" hreflang="fr" title="Français"><span>Français</span></a></li><li class="lang-es"><a href="http://localhost/tshirts/?lang=es" hreflang="es" title="Español"><span>Español</span></a></li></ul><div class="qtrans_widget_end"></div><script type="text/javascript">
// <![CDATA[
var lc = document.getElementById('mqtranslate-2-chooser');
var s = document.createElement('select');
s.id = 'qtrans_select_mqtranslate-2-chooser';
lc.parentNode.insertBefore(s,lc);
var sb = document.getElementById('qtrans_select_mqtranslate-2-chooser');
var o = document.createElement('option');
var l = document.createTextNode('Deutsch');
o.value = 'http://localhost/tshirts/?lang=de';
o.appendChild(l);
sb.appendChild(o);
var sb = document.getElementById('qtrans_select_mqtranslate-2-chooser');
var o = document.createElement('option');
var l = document.createTextNode('English');
o.selected = 'selected';
o.value = 'http://localhost/tshirts/';
o.appendChild(l);
sb.appendChild(o);
var sb = document.getElementById('qtrans_select_mqtranslate-2-chooser');
var o = document.createElement('option');
var l = document.createTextNode('Français');
o.value = 'http://localhost/tshirts/?lang=fr';
o.appendChild(l);
sb.appendChild(o);
var sb = document.getElementById('qtrans_select_mqtranslate-2-chooser');
var o = document.createElement('option');
var l = document.createTextNode('Español');
o.value = 'http://localhost/tshirts/?lang=es';
o.appendChild(l);
sb.appendChild(o);
s.onchange = function() { document.location.href = this.value;}
lc.style.display='none';
// ]]>
</script>
EDIT: Changes after Joe's comment below. Now always highlighting "English" no matter which language page it lands on.
var sb = document.getElementById('qtrans_select_mqtranslate-2-chooser');
var o = document.createElement('option');
var l = document.createTextNode('Deutsch');
o.selected = document.location.href.match(/\/de\//) !== null
o.value = 'http://localhost/tshirts/?lang=de';
o.appendChild(l);
sb.appendChild(o);
var sb = document.getElementById('qtrans_select_mqtranslate-2-chooser');
var o = document.createElement('option');
var l = document.createTextNode('English');
o.selected = document.location.href.match(/\/(de|fr|es)\//) === null
o.value = 'http://localhost/tshirts/';
o.appendChild(l);
sb.appendChild(o);