| Christian J |
Oct 23 2006, 06:11 PM
Post
#1
|
|
. ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: WDG Moderators Posts: 4,838 Joined: 10-August 06 Member No.: 7 |
Not only PHP sorts the Swedish letters å, ä and ö incorrectly, now I noticed that javascript does the same, and also in Danish and Norwegian. The arrays below should be in the correct order for each language:
CODE window.onload=function() { var se=['å','ä','ö']; // Swedish var dk=['æ','ø','å']; // Danish, apparently same as Norwegian alert(se.sort()); alert(dk.sort()); } Note that Danish and Norwegian use a different order than Swedish. But in the sorted javascript alerts the Swedish letters are incorrectly sorted as "ä,å,ö", while Danish and Norwegian are (again incorrectly) sorted as "å,æ,ø". The same error appear in IE, Opera and Firefox. At least Opera's Norwegian creators should know their own alphabet, so am I correct in assuming that all three browser vendors deliberately follow some flawed convention? |
![]() ![]() |
| Liam Quinn |
Oct 23 2006, 08:03 PM
Post
#2
|
|
WDG Founder ![]() ![]() ![]() Group: Root Admin Posts: 51 Joined: 2-August 06 From: Canada Member No.: 1 |
The default sort algorithm in JavaScript is based purely on the Unicode code point. If you want a locale-sensitive sort order, you can use this:
CODE function localeSort(string1, string2) { return string1.toString().localeCompare(string2.toString()); } var se=['å','ä','ö']; // Swedish var dk=['æ','ø','å']; // Danish, apparently same as Norwegian alert(se.sort(localeSort)); alert(dk.sort(localeSort)); That should use the locale configured on the user's system. If you want to use a specific locale regardless of the user's locale, I think you're stuck with writing the code for the locale-specific rules yourself in the function you pass to sort(). |
Christian J Incorrect sorting of the Scandinavian alphabets Oct 23 2006, 06:11 PM
Darin McGrew Does PHP allow you to specify the locale? The defa... Oct 23 2006, 06:55 PM
Christian J
Does PHP allow you to specify the locale?
It do... Oct 24 2006, 05:48 AM
Liam Quinn
[quote name='Darin McGrew' post='3248' date='Oct ... Oct 24 2006, 07:48 PM
Christian J
One problem is that you have the Danish and Swedi... Oct 25 2006, 07:04 AM
Brian Chandler
One problem is that you have the Danish and Swed... Oct 26 2006, 12:32 AM
Christian J
The default sort algorithm in JavaScript is based... Oct 24 2006, 07:46 AM
Liam Quinn
Do you mean the user's OS or browser langua... Oct 24 2006, 08:05 PM
pandy
According to wikipedia the first 256 code points... Oct 25 2006, 06:02 PM
Darin McGrew I can't say whether I'm "a typical En... Oct 24 2006, 01:49 PM
Christian J
I can't say whether I'm "a typical E... Oct 24 2006, 02:21 PM
Darin McGrew But what if you (the English-speaking user) don... Oct 24 2006, 02:36 PM![]() ![]() |
|
Lo-Fi Version | Time is now: 20th June 2013 - 01:10 AM |