Reputation: 3870
I'm trying to convert Turkish characters to readable slug. But it fails with undefined...
What is the problem here?
Html
<div id="converter">Fıstıkçı Şahap Çık Dışarı Dağlarda Oyna</div>
Js:
String.prototype.sluggable = function(){
var string = this;
var letters = {
"İ": "i",
"I": "i",
"ı": "i",
"Ş": "s",
"ş": "s",
"Ğ": "g",
"ğ": "g",
"Ü": "u",
"ü": "u",
"Ö": "o",
"ö": "o",
"Ç": "c",
"ç": "c"
};
string = string.replace(/([İIıŞşĞğÜüÇçÖö])+/g, function(letter){ return letters[letter]; });
return string.toLowerCase().replace(/([^a-zA-Z0-9])+/g, '_');
}
var $text = $('#converter').text();
$('#converter').text($text.sluggable());
Demo: http://jsfiddle.net/Fr8Nq/
Upvotes: 1
Views: 120
Reputation: 145428
Change your regular expression to the following:
/[İIıŞşĞğÜüÇçÖö]/g
You don't need to match the sequence of characters but replace them individually.
DEMO: http://jsfiddle.net/Fr8Nq/1/
Upvotes: 2