Skip to content

Instantly share code, notes, and snippets.

@haldun
Created June 28, 2011 06:03
Show Gist options
  • Select an option

  • Save haldun/1050583 to your computer and use it in GitHub Desktop.

Select an option

Save haldun/1050583 to your computer and use it in GitHub Desktop.
Fix for turkish locale compare for browsers
(function(){
String.prototype.originalLocaleCompare = String.prototype.localeCompare;
var alphabet = ["A", "a", "B", "b", "C", "c", "Ç", "ç", "D", "d", "E", "e",
"F", "f", "G", "g", "Ğ", "ğ", "H", "h", "I", "ı", "İ", "i",
"J", "j", "K", "k", "L", "l", "M", "m", "N", "n", "O", "o",
"Ö", "ö", "P", "p", "R", "r", "S", "s", "Ş", "ş", "T", "t",
"U", "u", "Ü", "ü", "V", "v", "Y", "y", "Z", "z"];
String.prototype.localeCompare = function(b) {
var a = this;
if (a == b) {
return 0;
}
for (var i = 0, _len = Math.min(a.length, b.length); i < _len; i++) {
var x = a.charAt(i), y = b.charAt(i);
if (x === y) {
continue;
}
var ix = alphabet.indexOf(x), iy = alphabet.indexOf(y);
if (ix != -1 && iy != -1) {
return ix < iy ? -1 : 1;
}
return x.originalLocaleCompare(y);
}
};
})();
@haldun

haldun commented Jun 28, 2011

Copy link
Copy Markdown
Author

Fixed for IE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment