You Shipped a Turkish Localization. Now "INFO" Lowercases to "ınfo" and Your String Matching Is Broken.
We shipped the Turkish localization on a Thursday. I remember because I was pleased with myself. Forty-one screens, a native speaker reviewed every string, the screenshots looked great.
By Friday morning there were three support emails from Istanbul, and they all said roughly the same thing: the app is in Turkish now, thank you, and also nothing loads anymore.
Nothing had changed in the networking code. Nothing had changed in the models. The only thing in that release was a folder of translated strings. And yet the feed was empty, the image picker rejected every GIF, and one user couldn’t log in with an email address they’d used for two years.
The translation was fine. The problem was a letter. Specifically, the letter I.
Turkish has four of them
English has two versions of this letter: I and i. One is the capital of the other. You’ve never thought about it.
Turkish has four, and they’re two separate letters:
Iandı: capital and lowercase dotless iİandi: capital and lowercase dotted i
So in Turkish, the lowercase of I is ı. Not i. And the uppercase of i is İ. Not I. This isn’t a quirk or an edge case. It’s how the alphabet works, and Foundation knows it:
import Foundation
let turkish = Locale(identifier: "tr_TR")
"INFO".lowercased(with: turkish) // "ınfo"
"TITLE".lowercased(with: turkish) // "tıtle"
"gif".uppercased(with: turkish) // "GİF"
"quit".uppercased(with: turkish) // "QUİT"
Every one of those is correct Turkish casing. Every one of them is also a string that no longer equals what your code expects it to equal.
"ınfo" == "info" is false. They look nearly identical in most fonts, which makes this a truly special bug to stare at in a debugger.
Where I’d planted the mines
Here’s the embarrassing part. Nobody on the team ever typed Locale(identifier: "tr_TR"). What we’d typed, in a dozen places over three years, was this:
let level = LogLevel(rawValue: payload.level.localizedLowercase)
or its cousin:
let key = header.lowercased(with: .current)
Why? Because it sounds more correct. “Localized” feels like the responsible, grown-up choice, the same way wearing a helmet does. Autocomplete offers it right next to plain lowercased(). And for three years the two behaved identically, so nothing ever told us otherwise.
Then the locale became Turkish, and these all broke at once:
// Server sends "INFO", enum is case info
LogLevel(rawValue: "INFO".localizedLowercase) // nil ("ınfo")
// "Is this a GIF?"
["gif", "png", "jpg"].contains("GIF".localizedLowercase) // false ("gıf")
// Normalizing an email before login
"INFO@EXAMPLE.COM".localizedLowercase // "ınfo@example.com"
// Case-insensitive header lookup
"Content-Type".localizedUppercase // "CONTENT-TYPE". Phew.
"Authorization".localizedUppercase // "AUTHORİZATİON". Not phew.
That last pair is what makes this bug so slippery. Only strings containing an i or an I are affected. "png" survives. "gif" doesn’t. "Content-Type" survives. "Authorization" doesn’t. Half your enum cases parse and the other half silently fall into the default: branch.
So the bug report isn’t “everything is broken.” It’s “some things are broken, for some users,” which is the worst kind.
Why it waited for the localization
This is the bit that fooled me, and I think it fools most people.
I’d assumed that Turkish users had been running our code with a Turkish locale all along. They’d had the app for years. If localizedLowercase were going to blow up, surely it would have done so already?
It hadn’t, because of how Locale.current picks its language. In my experience, it doesn’t simply mirror the device language. It reflects the language the app is actually running in. If your app only ships English, a user in Ankara with a fully Turkish phone still runs your app in English, and Locale.current comes back as something like en_TR: English language, Turkish region. English casing rules. Everything works.
The day you add tr.lproj to the bundle, that same user’s app starts running in Turkish, Locale.current becomes tr_TR, and every localizedLowercase in your codebase switches alphabets.
Adding a strings file changed the behavior of code that had nothing to do with strings files. That’s why the diff looked so innocent. The same applies to Azerbaijani, which uses the same four letters.
It’s the same family as the decimal separator bug, where a user’s region setting leaks into a string a machine has to read. Different setting, same mistake.
The rule: who is going to read this string?
There are two kinds of strings in your app, and they need opposite treatment.
Strings for humans. Button titles, headings, a name shown in a list. Turkish users want "title" to become "TİTLE", because "TITLE" is misspelled in their language. Use the localized APIs here. This is exactly what they’re for.
Strings for machines. Enum raw values, JSON keys, header names, file extensions, URL schemes, hex, email addresses, cache keys, anything you compare against a constant. These aren’t in any human language. They’re in ASCII-flavored Protocol, and Protocol has no dotless ı.
For machine strings, the fix is the plain standard library method:
"INFO".lowercased() // "info" on every device on Earth
"gif".uppercased() // "GIF"
Swift’s own lowercased() and uppercased() take no locale and don’t consult one. Same input, same output, in Istanbul or Idaho.
If you’re calling a Foundation API that wants a locale, be explicit about wanting none of the user’s:
let posix = Locale(identifier: "en_US_POSIX")
header.lowercased(with: posix)
en_US_POSIX is the same “this is for machines” locale you pin on a DateFormatter when parsing API dates. It exists precisely so that user settings can’t reach in and rearrange your data.
Better still, skip the case conversion entirely when all you want is a comparison:
extension String {
/// For identifiers, protocol tokens and anything machine-readable.
func matchesIdentifier(_ other: String) -> Bool {
compare(other, options: .caseInsensitive,
locale: Locale(identifier: "en_US_POSIX")) == .orderedSame
}
}
fileExtension.matchesIdentifier("gif")
One helper with an honest name, and nobody has to remember which of the five lowercase-ish APIs is the safe one.
The other direction bites too
Before you go replace every localizedLowercase with lowercased(), a warning: the plain version is wrong for human text, just more quietly.
"İstanbul".lowercased() == "istanbul" // false
The standard library follows Unicode’s default mapping, where İ lowercases to an i followed by a combining dot. It renders as one character and it’s two Unicode scalars. A Turkish user searching their contacts for “istanbul” won’t match “İstanbul” if you’ve hand-rolled the search with lowercased() on both sides.
So for searching and sorting what people typed, don’t case-fold by hand at all. Use the APIs built for it, like localizedStandardContains, and let the system handle the alphabet it knows better than you do.
Machine strings: no locale. Human strings: the user’s locale. The bugs live wherever you used one tool for the other job.
Test it without flying to Turkey
You don’t need a Turkish device. You need the locale to be a parameter instead of an ambient global, so a test can pass a hostile one.
import Testing
import Foundation
struct IdentifierCasingTests {
@Test(arguments: ["en_US", "tr_TR", "az_AZ", "de_DE"])
func logLevelParsesInEveryLocale(identifier: String) {
let locale = Locale(identifier: identifier)
let parser = LogLevelParser(locale: locale)
#expect(parser.parse("INFO") == .info)
#expect(parser.parse("Critical") == .critical)
}
}
If LogLevelParser uses the injected locale for casing, the tr_TR and az_AZ cases fail on the spot. Then you delete the locale parameter, because a parser for machine tokens shouldn’t have one, and the test stays behind as a tripwire.
Two more cheap checks:
- Grep. Search the project for
localizedLowercase,localizedUppercase,localizedCapitalized,lowercased(with:anduppercased(with:. For each hit, ask who reads the result. I had fourteen hits. Eleven were machine strings. - Run it. In your Xcode scheme, set App Language to Turkish and click through the app once. If your project has a Turkish localization, or you add a throwaway one, this takes five minutes and finds the bugs your tests didn’t think of.
And pick test words with an i in them. A fixture full of "png", "post" and "user" will pass in Turkish forever and tell you nothing. If you’re doing localization properly, the accessibility and localization lesson covers the rest of the checklist; this one deserves a line on it.
The fix was eleven deletions
The actual patch removed the word localized in eleven places and added one helper. That was it. A point release, a slightly sheepish changelog entry, and a reply to three very patient people in Istanbul.
What stuck with me is how reasonable the original code looked. Nobody wrote something lazy. Somebody reached for the API that sounded more careful, and it was more careful, about a question we weren’t asking. The same thing happens when your backend’s lowercase UUIDs meet Swift’s uppercase ones: two systems, each behaving correctly, disagreeing about what a string is.
Your enum cases aren’t written in English. They aren’t written in Turkish either. Stop asking the user’s phone how to spell them.
Share this post
Comments
Leave a comment
NativeFirst Team
EditorialThe NativeFirst team — engineers and designers building native Apple apps and writing the courses we wish we had when we started.