[swift-users] Localization in Swift.

Jens Alfke jens at mooseyard.com
Tue Nov 1 11:08:49 CDT 2016

> On Nov 1, 2016, at 1:53 AM, Zhao Xin via swift-users <swift-users at swift.org> wrote:
> I began to realize that` \(count)` was not dealed well in localization. The compiler calculated the full string then looking for the translation, instead of looking for the translation first.

NSLocalizedString was designed (in the 1990s) to be used with methods like String(format:…) that take printf-style “%”-substituted format strings.
Swift’s string interpolation is obviously a different mechanism entirely.

I suspect that Swift interpolation won’t work well for localized strings because the string and the code are so tightly connected. Localization very often needs to change the order of parameters, for instance. It’s also unclear where things like number formatting happen in Swift interpolation; when localizing a string, the conversion needs to be done using the same locale as the string lookup, which might not happen if the string-to-number conversion is separate and uses the default locale.


More information about the swift-users mailing list