Turkish case conversion in JavaScript

Coming back to this years later to provide more up to date solution.

There is no need for the hack below,

just use
String.toLocaleUpperCase() and String.toLocaleLowerCase()

"dinç".toLocaleUpperCase('tr-TR') // "DİNÇ"

All modern browsers support this now.


[ OLD, DO NOT USE THIS ]

Try these functions

String.prototype.turkishToUpper = function(){
    var string = this;
    var letters = { "i": "İ", "ş": "Ş", "ğ": "Ğ", "ü": "Ü", "ö": "Ö", "ç": "Ç", "ı": "I" };
    string = string.replace(/(([iışğüçö]))+/g, function(letter){ return letters[letter]; })
    return string.toUpperCase();
}

String.prototype.turkishToLower = function(){
    var string = this;
    var letters = { "İ": "i", "I": "ı", "Ş": "ş", "Ğ": "ğ", "Ü": "ü", "Ö": "ö", "Ç": "ç" };
    string = string.replace(/(([İIŞĞÜÇÖ]))+/g, function(letter){ return letters[letter]; })
    return string.toLowerCase();
}

// Example
"DİNÇ".turkishToLower(); // => dinç
"DINÇ".turkishToLower(); // => dınç

I hope they will work for you.

Leave a Comment