JavaScript · i18n · TypeScript · Frontend
Turkish Characters in JavaScript: The Dotted I, Sorting, Search and Slugs
The Turkish-I problem and other Turkish text bugs in JavaScript: locale-aware casing, sorting with Intl.Collator, accent-insensitive search, slugs, regex and number parsing.

Most of the sites I build serve Turkish and English visitors: health-tourism clinics, logistics companies, corporate sites, and this portfolio. Turkish looks like any Latin-script language until it breaks something. City dropdowns sort Çanakkale after Zonguldak, a search for "istanbul" misses "İSTANBUL", and code that compares uppercase keys works everywhere except on a Turkish user's browser. Here is what goes wrong and the fixes I now use by default.
The Turkish I: four letters, not two
English has i and I. Turkish has two separate letters, each with its own upper and lower case:
| Lowercase | Uppercase | Name |
|---|---|---|
i | İ | dotted i |
ı | I | dotless i |
JavaScript's default case conversion follows the language-neutral Unicode rules, which are right for English and wrong for Turkish:
'i'.toUpperCase(); // 'I' (Turkish expects 'İ')
'i'.toLocaleUpperCase('tr-TR'); // 'İ'
'I'.toLocaleLowerCase('tr-TR'); // 'ı'
'İ'.toLowerCase(); // 'i̇' — 'i' plus U+0307, length 2!
That last line is the nasty one. A string that looks like istanbul after toLowerCase() contains an invisible combining dot, so equality checks and lookups fail silently.
Rule 1: never use the default locale for identifiers
toLocaleUpperCase() with no argument uses the runtime's locale. On a Turkish system, this code breaks:
const method = input.toLocaleUpperCase(); // 'id' → 'İD' on a Turkish browser
if (method === 'ID') { /* never true for Turkish users */ }
The rule I follow: for machine identifiers (keys, enum values, HTTP methods, file extensions) use toUpperCase() / toLowerCase(), which are locale-independent. For human text shown to users, pass the locale explicitly: toLocaleUpperCase('tr-TR') for Turkish content, 'en' for English. Never rely on the implicit default.
The same applies to CSS. text-transform: uppercase respects the lang attribute, so <html lang="tr"> correctly turns "iletişim" into "İLETİŞİM". If a Turkish page is marked lang="en", buttons show "ILETIŞIM". Get lang right per page; it matters for SEO too, as covered in hreflang for multilingual sites.
Rule 2: sort with Intl.Collator
Array.prototype.sort() compares UTF-16 code units, so every letter outside ASCII lands after Z:
const cities = ['Zonguldak', 'Çanakkale', 'Ankara', 'İzmir', 'Şanlıurfa', 'Iğdır', 'Ödemiş', 'Ordu'];
cities.sort();
// Ankara, Iğdır, Ordu, Zonguldak, Çanakkale, Ödemiş, İzmir, Şanlıurfa
const trCollator = new Intl.Collator('tr');
cities.sort(trCollator.compare);
// Ankara, Çanakkale, Iğdır, İzmir, Ordu, Ödemiş, Şanlıurfa, Zonguldak
The collator knows the Turkish alphabet (A B C Ç D … I İ … O Ö … S Ş …). Create it once and reuse it; constructing a collator inside a sort comparator is slow on long lists. If you sort on the server, the same API works in Node.js, which ships with full ICU data.
Rule 3: fold text for search
Users type without Turkish characters all the time: "saglik turizmi", "istanbul", "gumruk". For search and filtering, compare a folded form of both sides:
export function foldTurkish(text: string): string {
return text
.toLocaleLowerCase('tr-TR') // İ → i, I → ı
.replace(/ı/g, 'i') // ı has no decomposition, map it by hand
.normalize('NFD') // ç → c + ◌̧, ş → s + ◌̧, ğ → g + ◌̆ ...
.replace(/\p{M}/gu, ''); // drop combining marks
}
foldTurkish('İSTANBUL'); // 'istanbul'
foldTurkish('ISTANBUL'); // 'istanbul'
foldTurkish('Gümrük'); // 'gumruk'
Lowercasing with the Turkish locale first is what makes both İSTANBUL and ISTANBUL work. NFD handles ç, ğ, ö, ş and ü, but ı has no decomposed form, so it needs an explicit replacement.
Why not Intl.Collator('tr', { sensitivity: 'base' })? Because in Turkish collation c and ç are different letters, not accent variants, so it won't match "cesme" to "Çeşme". For search, folding is what users expect; for sorting, keep the collator.
Rule 4: slugs from the same fold
Turkish slugs should be ASCII so URLs stay readable everywhere. This blog's Turkish slugs, like hizli-kurumsal-web-sitesi-dersleri, are plain ASCII for that reason. The same fold produces them:
export function slugify(title: string): string {
return foldTurkish(title)
.replace(/[^a-z0-9]+/g, '-')
.replace(/^-+|-+$/g, '')
.slice(0, 80);
}
slugify('Sağlık Turizmi İçin Hızlı Site'); // 'saglik-turizmi-icin-hizli-site'
Rule 5: regex needs Unicode properties
\w means [A-Za-z0-9_], so validating a name field with it rejects "Gül" and "Şahin". Use Unicode property escapes with the u flag:
/^\w+$/.test('Gül'); // false
/^[\p{L}\s'-]+$/u.test('Gül Şahin'); // true
The same applies to word-boundary tricks: \b is also ASCII-based, so highlighting a search term with \b fails next to Turkish letters.
Rule 6: numbers and money
Turkish uses a dot for thousands and a comma for decimals. Formatting is easy; parsing is where bugs hide:
new Intl.NumberFormat('tr-TR', { style: 'currency', currency: 'TRY' }).format(1234.5); // '₺1.234,50'
parseFloat('1.234,5'); // 1.234 — silently wrong
Don't parse localized strings with parseFloat. Use <input type="number"> or inputmode="decimal" and normalise explicitly (strip thousands separators, swap the comma) before sending a plain number to the API.
Don't forget the font
Even with perfect string handling, a font subset without Latin Extended renders ğ, ş, ı and İ in a fallback font. Make sure the latin-ext subset is loaded; the details are in web font performance.
Conclusion
Turkish text bugs come from defaults: default locale, default sort, ASCII regex, parseFloat. Use locale-independent case conversion for identifiers and explicit tr-TR for human text, sort with Intl.Collator, fold both sides for search, build slugs from the same fold and validate with \p{L}. Put these helpers in one module and the whole team stops rediscovering the dotted I. For the UI translation side, see multilingual React apps with i18next.


