I have used jquery to sort a list of country names after the user changes the language code of the page (via a language select list). Here is a related post.
The translaion of country names appears to operate correctly, but the sorting (A-Z) of the translated country names does not quite work.
I have noticed that when a country name has a diaeresis / diacratic mark to the 1st letter of the country name, the said country name is relegated to the bottom of the list.
When the English country names have been translated to the German language. The country names with diaeresis / diacratic marks appear last. For example, the counrty name Österreich (Austria - in the English language) should be sorted after country names beginning with the letter O.
Is there a certain trick to sorting that will include letters of words with diaeresis / diacratic marks?
Here is a visual example of my dilema:
Here is my jQuery code:
function sortAddressTypes() {
// sort the address country style types list (country name) in alphabetical order after language code has changed.
var selected = $("#id_address_country_style_type").val(); // preserve the users selected value.
var options = $('#id_address_country_style_type option');
var arr = options.map(function(_, o) {
return {t: $(o).text(), v: o.value};
}).get();
arr.sort(function(o1, o2) {
return o1.t.toLowerCase() > o2.t.toLowerCase() ? 1 : o1.t.toLowerCase() < o2.t.toLowerCase() ? -1 : 0;
});
options.each(function(i, o) {
console.log(i);
o.value = arr[i].v;
$(o).text(arr[i].t);
});
$("#id_address_country_style_type").val(selected); // assign the preserved users selected value.
}