I am using jquery autocomplete plugin to search in a long list of names. It works fine for all latin and english characters, but with turkish characters I have problems, as the
After years from the last reply, I just ran into the same problem.
Accent mapping is not good enough for Turkish because it is still matching "I" with "i" and vice versa. However, lowercase "I" is "ı" and uppercase "i" is "İ" in Turkish. So, when I type "I", "İzmir" should NOT be a match and when I type "İ", "Iğdır" should NOT be a match.
So I used the following:
function toLowerTurkish(str) {
var letters = {
'Ç': 'ç', 'Ğ': 'ğ', 'I': 'ı', 'İ': 'i', 'Ö': 'ö', 'Ş': 'ş', 'Ü': 'ü',
};
str = str.replace(/(([ÇĞIİÖŞÜ]))/g, function(letter) { return letters[letter]; });
return str.toLowerCase();
}
function containsTurkish(txt, str) {
return toLowerTurkish(txt).indexOf(toLowerTurkish(str)) >= 0;
}
var itemList = [
{ label: 'İzmir', value: 'İzmir' },
{ label: 'istanbul', value: 'istanbul' },
{ label: 'Iğdır', value: 'Iğdır' },
{ label: 'ısparta', value: 'ısparta' }
];
function autocompleteSourceTurkish(request, response) {
var matchList = [];
itemList.forEach(function(item, index) {
if (containsTurkish(item.label, request.term)) matchList.push(item);
});
response(matchList);
}
$(function() {
$('#itemMenu').autocomplete({
source: autocompleteSourceTurkish
});
});
http://jsfiddle.net/emfy5gf9/